I want to write a SQL function that returns
true if a certain
INSERT inserted a row and
false if no line has been inserted. In this case of use, we know that at most one line can be inserted.
I came up with the following solution:
create function test () returns a boolean $$ with dummy like ( insert in ... select ... from ... where ... - this will limit to at most one row returns true ) select exists (select true from manikin); $$ volatile sq language;
It seems to work well, but it is rather clumsy and prolix, in my opinion. Is there anything better?
I first wanted to write the following:
create function test () returns a boolean $$ insert in ... select ... from ... or ... return true; $$ volatile sq language;
The problem now is that no
no is returned when no line has been inserted.