I have the following query right now which returns the id after a successful insert
INSERT INTO match (match_id) values(?) ON CONFLICT DO NOTHING RETURNING id
How can I make this return the id
of the row which already exists on conflict?
I have the following query right now which returns the id after a successful insert
INSERT INTO match (match_id) values(?) ON CONFLICT DO NOTHING RETURNING id
How can I make this return the id
of the row which already exists on conflict?
Use ON CONFLICT DO UPDATE
instead to ensure that the query operates on a row and so can return something:
CREATE TABLE match(id serial PRIMARY KEY);
INSERT INTO match (id) VALUES (1)
ON CONFLICT (id) DO UPDATE
SET id = excluded.id
RETURNING id;