-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conflict target's where should not have a table name #191
Comments
Hrmmm looking at the Postgres docs, it looks like the where clause for the conflict is for an index_predicate, not a proper conditional block. So, that would be a bug in MoSQL. However, I think you wanted your where clause to be for the update, right? If you move your {
type: 'insert',
table: 'entries',
values: [
{
orgId: '...',
otherId: '...',
amount: 1200,
},
],
conflict: {
target: {
columns: [
'orgId',
'otherId',
],
},
action: {
update: {
amount: '$excluded.amount$',
},
where: {
isDeleted: false,
},
},
},
} Result insert into "entries" ("orgId",
"otherId",
"amount")
values ($1, $2, $3) on conflict ("orgId", "otherId")
where "entries"."isDeleted" is false do
update
set "amount" = "excluded"."amount" where "entries"."isDeleted" is false
-- Values:
-- [
-- "...",
-- "...",
-- 1200
-- ] |
Well, I forgot to mention that I want to handle conflicts on the partial unique index. It is defined with In that case conflict target cannot be just a list of columns since that doesn't match the index. If I write manually query as
it works perfectly. |
Ahhhh I see. You can always fallback to using the {
type: 'insert',
table: 'entries',
values: [
{
orgId: '...',
otherId: '...',
amount: 1200,
},
],
conflict: {
target: {
columns: [
'orgId',
'otherId',
],
where: {
$custom: ['"isDeleted" is false']
}
},
action: {
update: {
amount: '$excluded.amount$',
},
},
},
} Result insert into "entries" ("orgId",
"otherId",
"amount")
values ($1, $2, $3) on conflict ("orgId", "otherId")
where "isDeleted" is false do
update
set "amount" = "excluded"."amount"
-- Values:
-- [
-- "...",
-- "...",
-- 1200
-- ] Not super ideal I know |
Yeah, I forgot about it. |
It is nicely stated in the conflict helper that where doesn't need a table name, but it still gets it.
mongo-sql/helpers/query/conflict.js
Line 69 in 1351b48
If I try something like
The result is
The text was updated successfully, but these errors were encountered: