I am trying to use a CTE to insert some random data into a table -
create table foo (id integer)with x as (select random()) insert into foo (id) select x from x
This gives an error:ERROR: column "id" is of type integer but expression is of type record
Just the CTE with select
works:
with x as (select random())-- insert into foo (id) select x from x
I am also unable to typecast:
with x as (select random()) insert into foo (id) select x::integer from x
This gives an error: ERROR: cannot cast type record to integer
.
What's going wrong and how do I fix it?