At now I use code like that
create function something()
returns boolean
as
$$
begin
if exists (select 1 from some_table where some_cond) then
return false;
end if;
insert into some_table (value)
values (2)
-- on conflict do !!! return false
returning true;
end
$$
language 'plpgsql';
Is there a way to return value from on conflict
section without defining a variable or temp table in one query?
Best Answer
You can handle exceptions.
If you try to insert a duplicate key:
db<>fiddle here