1 | initial version |
Yes, it is possible to use both a column and a where clause in the INSERT .. ON CONFLICT statement in Postgres.
Here's an example:
INSERT INTO mytable (id, name, age)
VALUES (1, 'John', 25)
ON CONFLICT (id)
WHERE name <> excluded.name
DO UPDATE
SET age = excluded.age;
In this example, the ON CONFLICT clause specifies that if a record with the same id already exists in the table, the update should be performed only if the name in the existing record is different from the name in the new record being inserted. If the names match, the update is not performed.