test=# create table chary(key serial primary key, val text unique);CREATE TABLE
test=*# with ok as (select * from chary where val = 'blafasel'), neu as (insert into chary (val) values ('blafasel') on conflict do nothing returning *) select * from ok union all select * from neu;
key | val
-----+----------
1 | blafasel
(1 row)
test=*# with ok as (select * from chary where val = 'blafasel'), neu as (insert into chary (val) values ('blafasel') on conflict do nothing returning *) select * from ok union all select * from neu;
key | val
-----+----------
1 | blafasel
(1 row)
test=*# select * from chary;
key | val
-----+----------
1 | blafasel
(1 row)
test=*# with ok as (select * from chary where val = 'foobar'), neu as (insert into chary (val) values ('foobar') on conflict do nothing returning *) select * from ok union all select * from neu;
key | val
-----+--------
3 | foobar
(1 row)
test=*# with ok as (select * from chary where val = 'foobar'), neu as (insert into chary (val) values ('foobar') on conflict do nothing returning *) select * from ok union all select * from neu;
key | val
-----+--------
3 | foobar
(1 row)
test=*# select * from chary;
key | val
-----+----------
1 | blafasel
3 | foobar
(2 rows)
test=*#