Quantcast
Channel: Active questions tagged cte - Database Administrators Stack Exchange
Viewing all articles
Browse latest Browse all 207

Unable to use INSERT within CTE

$
0
0

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?


Viewing all articles
Browse latest Browse all 207

Trending Articles