fix - Where example for conflict+merge #564
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
The current documentation for
where
after onConflict + merge does not seem correct.Following the example, we receive the error
column reference "x" is ambiguous
.Root cause
This is because in the
where
condition of a onConflict + merge, we have access to both thetable
andexcluded
.https://www.postgresql.org/docs/current/sql-insert.html
https://dba.stackexchange.com/a/224167
So the alias of the column name is ambiguous between the
table
andexcluded
.We can actually see the table name being directly referenced in the test case that this scenario was created for https://github.com/knex/knex/pull/4148/files#diff-57a163701cfad49b7c6cbdfb102667277345ba8de7e575f6966269b0c0d8d3a0R1557
Solution
We could update with a custom where condition to actually use table name
https://github.com/knex/knex/blame/4ca3dd5bc28e0665c5bed55026fac2ec45489d81/lib/dialects/postgres/query/pg-querycompiler.js#L37
but implicitly choosing one or the other feels dangerous.
So this proposal is just to fix the documentation that shows the feature to work.