Skip to content

Conversation

@YongSeok-Choi51
Copy link

@YongSeok-Choi51 YongSeok-Choi51 commented Nov 11, 2025

Related Issue

[Literal Value treated as Column name in Where Clause (Postgres Database)]

[closed previous PR]

Issue Detail

db // Knex instance

// Basic query that includes a join with literal join value
const qb = db('table_a').innerJoin('table_b', join => {
  join.onVal('table_b.id', '123')
})

// Executing select on this query results in proper formatting of literal value
// SQL: select "table_a"."id" from "table_a" inner join "table_b" on "table_b"."id" = '123' 👈👈 (This Allows in Postgres!)
console.log(qb.select('table_a.id').toQuery())

// Executing delete on this query results in literal value being formatted as if it were a column name
// SQL: delete from "table_a" using "table_b" where "table_b"."id" = "123"  👈👈 (This is Not Allowed in Postgres. 123 must be single quoted like '123')
console.log(qb.delete().toQuery())

Description (Solution)

i solved this issue by fixing pg-querycompiler implementation

return this.config.wrapIdentifier(value, origImpl, queryContext);
}
return origImpl(value);
return origImpl(value, queryContext);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mercmobily hi!

i suggest the parameter queryContext pass to function origImpl because future usage (e.g. wrapIdentifierImpl or else)

please let me know what do you think 🙏

asColumn: true,
})
);
const clauseSql = this[clause.type](clause);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mercmobily The Code that you suggested is totally works... But, frankly i don't know how it works. event that code pass the test code

i'll dig in the code base.
please let me know if i need to do some fixing the code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants