I need to update the data, and if they are not in the database, then insert and return the key. Unfortunately, I can't use merge, on conflict and procedural blocks. Now I'm using the following query,
WITH _a AS (
UPDATE mytable1 SET name=expr1, last_name = expr2
WHERE empId = expr3
RETURNING empId
), _b AS (
INSERT INTO mytable1 (empId, name, last_name)
SELECT(expr3, expr1, expr2)
WHERE NOT EXISTS (SELECT * FROM _a)
RETURNING empId
but unfortunately, if the query inserts data, it returns the key, and if it updates, it doesn't.
Is it possible to somehow rewrite the request so that it always returns the key?