Syntax errors when using union with first/limit in 1.0.4
See original GitHub issueEnvironment
Knex version: 1.0.4 Database + version: PostgreSQL 13.4 OS: Debian
Bug
In 1.0.4 the behavior (order and wrapping) of union changed causing queries that previously worked to generate syntax errors.
One example is:
const results = await knex('accounts')
.select('last_name')
.unionAll(function () {
this.select('last_name').from('accounts');
})
.first();
expect(results).to.eql({ last_name: 'User' });
Which in 1.0.4 gives error: select "last_name" from "accounts" limit $1 union all select "last_name" from "accounts" - syntax error at or near "union"
.
But in 1.0.3 it generates select "last_name" from "accounts" union all select "last_name" from "accounts" limit ?
.
Another query that fails is
const results = await knex
.unionAll(
function () {
this.select('last_name').from('accounts');
},
function () {
this.select('last_name').from('accounts');
},
true
)
.first();
expect(results).to.eql({ last_name: 'User' });
with error: (select "last_name" from "accounts") union all (select "last_name" from "accounts") (limit $1) - syntax error at or near "("
I believe this change is introduced in https://github.com/knex/knex/pull/5030. Is this new behavior intended and we should rewrite our union queries?
This following is working, so it’s not that hard to update the queries but it seems like a breaking change?
const results = await knex
.unionAll(
function () {
this.select('last_name').from('accounts');
},
function () {
this.select('last_name').from('accounts');
}
)
.first();
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:9 (2 by maintainers)
Top GitHub Comments
Sorry for the wait, and thanks for all examples guys. I have find how to fix it and I added a lot of unit tests but still need more tests. I will push tomorrow at the end of day.
@fnatte @wa11a I will fix it as soon as possible (today or tomorrow).