Postgres Upsert: Created or Updated?

The excellent PostgreSQL database supports the following syntax for the common upsert SQL pattern:

INSERT INTO table(id, column1, column2)
VALUES (@id, @value1, @value2)
ON CONFLICT (id) DO UPDATE
SET
    column1=EXCLUDED.value1,
    column2=EXCLUDED.value2
RETURNING *

With this syntax, you can insert a new row with the given values, or update the existing row to the given values, using the row’s primary key (or other indexed key). Very handy!

But did the resulting upserted row insert or update?

Continue reading “Postgres Upsert: Created or Updated?”