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

Postgres: After inserting value returns primary key and need to update column using returned primary id

$
0
0

In a single query, I need to perform Insert and update on the insertion row. For example, I have a set of columns and its value to be inserted after getting the primary key, I need to update another column on the same row.I tried below query it does not work. Please help

With tempvar as (  INSERT INTO table_name(col1, col2, col3)    VALUES ('colval1','colval2','colval3')     RETURNING primarykeyid  )update table_name      set column_to_be_updated  = concat('value', 'value')  where primarykeyid  = (select * from tempvar)

Viewing all articles
Browse latest Browse all 207

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>