你可以做:
with id as ( select id from table_name where appid = 2 and name = 'xyz' ), i as ( insert table_name (appid, name) select 2, 'xyz'where not exists (select 1 from id) returning id )select idfrom idunion allselect idfrom i;

你可以做:
with id as ( select id from table_name where appid = 2 and name = 'xyz' ), i as ( insert table_name (appid, name) select 2, 'xyz'where not exists (select 1 from id) returning id )select idfrom idunion allselect idfrom i;