Join or clause can't compare to constants
See original GitHub issueCurrently, it doesn’t seem to be possible to generate a query like the following (in MySQL):
select * from `users` inner join `contacts` on `users`.`id` = `contacts`.`id` and `users`.`name` = 'mungo'
My test looks approximately like this. Basically, the on clause doesn’t work with the richness of the where clause, and it probably should. Of course, with integer values JS can tell the difference between strings and identifiers, but not for strings, so it’s escaping a string value as an identifier in all cases.
This is needed because for left and right joins, you can’t move the on clause to the where clause.
it("complex join with string value", function() {
testsql(qb().select('*').from('users').join('contacts', function(qb) {
qb.on('users.id', '=', 'contacts.id').andOn('users.name', 'mungo');
}), {
mysql: {
sql: 'select * from `users` inner join `contacts` on `users`.`id` = `contacts`.`id` or `users`.`name` = \'mungo\'',
bindings: []
},
default: {
sql: 'select * from "users" inner join "contacts" on "users"."id" = "contacts"."id" or "users"."name" = \'mungo\'',
bindings: []
}
});
});
I’ll probably work on a patch/pull request later.
Issue Analytics
- State:
- Created 9 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Join or clause can't compare to constants · Issue #626 - GitHub
My test looks approximately like this. Basically, the on clause doesn't work with the richness of the where clause, and it probably should....
Read more >The type of one of the expressions in the join clause is ...
I'm getting this error: The type of one of the expressions in the join clause is incorrect. Type inference failed in the call...
Read more >Avoid using constants in an ORDER BY clause | Redgate
Phil Factor explains why an ORDER BY clause should always specify the sort columns using their names, or aliases, rather than using an ......
Read more >Cant use a condition comparing 2 variables
One workaround is to call Power Automate to validate the condition using two variables and return the response to PVA.
Read more >Chapter 5. EPL Reference: Clauses - Index of / - EsperTech
Variables can be used in an expression anywhere in a statement as well as in the output clause for dynamic control of output...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Important change I realized was needed while testing.
knex.raw(true)
is fine, but you can’t do the same for a string since it won’t be escaped. So the documented recommendation is to use a binding:I know this looks gross but I can’t think of a better way to address it.
As I can read, we always need to make something, maybe I can reopen it if anyone want to make a PR ?