Repository navigation
Closed
Labels
Description
Issue Description
When i create an index with where condition it does not match ON CONFLICT statement on upsert.
What are you doing?
PSQL Index:
CREATE UNIQUE INDEX ON "lists" ("sample", "example") WHERE ("deletedAt" IS NULL);Model Index:
indexes: [
{
unique: true,
fields: ['sample', 'example'],
where: {
deletedAt: null,
},
},
]Request:
await List.upsert(attributes, { transaction });What do you expect to happen?
It have to INSERT new record or UPDATE existing one based on uniq index condition.
INSERT INTO "lists" ("sample","example","createdAt","updatedAt") VALUES ($1,$2,$3,$4)
ON CONFLICT ("sample","example") WHERE deletedAt is NULL DO...What is actually happening?
Error:
original: error: there is no unique or exclusion constraint matching the ON CONFLICT specification
INSERT INTO "lists" ("sample","example","createdAt","updatedAt") VALUES ($1,$2,$3,$4)
ON CONFLICT ("sample","example") DO UPDATE SET...
Additional context
Seems like ON CONFLICT WHERE case does not covered. At least according to following PR code.
So, instead of mapping where condition into ON CONFLICT statement, the builder just ignore it.
Environment
- Sequelize version: 6.3.5
- Node.js version: v12.16.1
- Operating System: MacOs 10.15.7
Issue Template Checklist
How does this problem relate to dialects?
- I think this problem happens regardless of the dialect.
- I think this problem happens only for the following dialect(s): Psql
- I don't know, I was using PUT-YOUR-DIALECT-HERE, with connector library version XXX and database version XXX
Would you be willing to resolve this issue by submitting a Pull Request?
- Yes, I have the time and I know how to start.
- Yes, I have the time but I don't know how to start, I would need guidance.
- No, I don't have the time, although I believe I could do it if I had the time...
- No, I don't have the time and I wouldn't even know how to start.
Reacted by David, Pavel Khudyshkin, Arseniy Ivanov and Axel Manzano
Activity
deggertsen commentedon Feb 20, 2021
Ran into this issue today. Upsert fails where there is a unique constraint rather than simply updating the record with the new values. Tried to setup the unique constraint in an index like OP and then tried it as a separate constraint, both failed.
severity: 'ERROR', code: '23505', detail: 'Key (keys, content_id, content_type)=(Mount Pleasant, 1111111, xxxxx) already exists.',feat(model): add support for where clauses with ON CONFLICT queries
github-actions commentedon Oct 27, 2021
This issue has been automatically marked as stale because it has been open for 7 days without activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment or remove the "stale" label. 🙂