How to Retrieve id of inserted row when using upsert with WITH cluase in Posgres 9.5?
问题 I'm trying to do upset query in Postgres 9.5 using "WITH" with s as ( select id from products where product_key = 'test123' ), i as ( insert into products (product_key, count_parts) select 'test123', 33 where not exists (select 1 from s) returning id ) update products set product_key='test123', count_parts=33 where id = (select id from s) returning id Apparently I'm retrieving the id only on the updates and get nothing on insertions even though I know insertions succeeded. I need to modify