Given the following skeleton pl/pgsql function, how can I make it return true if the update was successful (something was actually updated) and false otherwise?
CREATE FUNCTION UpdateThingy(
/* input parameters */
) RETURNS BOOLEAN AS $$
BEGIN
UPDATE thingies SET /* blah blah */ WHERE /* blah blah */;
RETURN true;
END;
$$ LANGUAGE plpgsql;
Currently this will always return true, even if no rows where updated. I want to return false in the case of no rows being affected by the update.
After the UPDATE, you can obtain the number of updated rows using
GET DIAGNOSTICSor theFOUNDstatus variable as described in the manual:http://www.postgresql.org/docs/current/static/plpgsql-statements.html#PLPGSQL-STATEMENTS-DIAGNOSTICS