As instructed by this comment.
CREATE OR REPLACE FUNCTION test_upsert(
_parent_id int,
_some_text text)
RETURNS text
LANGUAGE plpgsql AS
$func$
DECLARE
a text;
BEGIN
INSERT INTO parent_tree (parent_id, some_text)
VALUES (_parent_id,_some_text)
ON CONFLICT DO NOTHING
RETURNING 'ok' into a;
return a;
IF NOT FOUND THEN return 'JUZ ISTNIEJE';
END IF;
END
$func$;
Not sure what this means:
IF NOT FOUND THEN return 'JUZ ISTNIEJE';If no conflict then return
ok, which makes sense. But when conflict it will yield null. Is it possible to BOTH haveon conflict do nothingalso returnnot okor when conflict happens, justraise notice parent_id should be unique?