我在PostgreSQL 9.5中有以下发现:
INSERT INTO chats ("user", "contact", "name")
VALUES ($1, $2, $3),
($2, $1, NULL)
ON CONFLICT("user", "contact") DO NOTHING
RETURNING id;
如果没有冲突,它会返回如下内容:
----------
| id |
----------
1 | 50 |
----------
2 | 51 |
----------
但如果存在冲突,则不会返回任何行:
----------
| id |
----------
I want to return the new id
columns if there are no conflicts or return the existing id
columns of the conflicting columns.
Can this be done? If so, how?