I have an INSERT
statement where I want to copy contents of one table to the other, and want to write the number of rows inserted into a log table. I tried this:
with upd as (
insert into tb1 OVERRIDING USER VALUE
select * from tb2
returning count(*) as num_rows_inserted
)
insert into month_log select * from upd;
But Postgres complains:
ERROR: aggregate functions are not allowed in RETURNING
LINE 4: returning count(*) as num_rows_inserted
^
SQL state: 42803
Character: 109
How can I return the number of rows without an aggregate?