You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Explain what kind of behaviour you are getting and how you think it should do
I'm using .forUpdate([]) with a list of table names. I would expect this:
.forUpdate(['table1', 'table2'])
to render this into the query:
FOR UPDATE OF "table1", "table2"
Error message
The above is instead rendering this into the query:
FOR UPDATE OF "table1" AS "0", "table2" AS "1"
These AS additions are causing errors in SQL:
ERROR: syntax error at or near "AS"
According to the PostgreSQL docs, AS cannot occur here, which is why this throws an error. (I linked to v12, but it is the same in the current version as well.) Indeed, if I print the query out, remove the AS "0" and AS "1" and run the query directly on the DB, the query returns data successfully.
Reduced test code, for example in https://npm.runkit.com/knex or if it needs real
database connection to MySQL or PostgreSQL, then single file example which initializes
needed data and demonstrates the problem.
const Knex = require('knex');
const knexPg = Knex({
client: 'pg',
});
(async function run() {
const query = knexPg.queryBuilder()
.select(['id'])
.from('table1')
.leftJoin('table2', 'table1.fk_id', 'table2.id')
.forUpdate(['table1', 'table2']);
console.log(query.toString());
})();
// Outputs the following:
// select "id" from "table1" left join "table2" on "table1"."fk_id" = "table2"."id" for update of "table1" as "0", "table2" as "1"
The text was updated successfully, but these errors were encountered:
Environment
Knex version: 0.95.14
Database + version: PostgreSQL 12.7 (
pg
8.7.1)OS: AWS RDS
Bug
I'm using
.forUpdate([])
with a list of table names. I would expect this:to render this into the query:
The above is instead rendering this into the query:
These
AS
additions are causing errors in SQL:According to the PostgreSQL docs,
AS
cannot occur here, which is why this throws an error. (I linked to v12, but it is the same in the current version as well.) Indeed, if I print the query out, remove theAS "0"
andAS "1"
and run the query directly on the DB, the query returns data successfully.database connection to MySQL or PostgreSQL, then single file example which initializes
needed data and demonstrates the problem.
The text was updated successfully, but these errors were encountered: