Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
377 views
in Technique[技术] by (71.8m points)

postgresql - Alias in KNEX with Postgres db

The code in knexjs like below

.select("resources.id")

will be translated to below SQL

SELECT "RESOURCES"."ID"

But PostgreSQL only recognized RESOURCES.ID , not"RESOURCES"."ID" as valid column

Is this a known issue? Is there any suggestion apart from using SQL raw?

question from:https://stackoverflow.com/questions/65866395/alias-in-knex-with-postgres-db

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You need to use the wrapIdentifier to remove the quotes

const knex = require('knex')({
    client: 'pg',
    wrapIdentifier: (value, origImpl, queryContext) => value});

http://knexjs.org/#Installation-wrap-identifier


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...