简体   繁体   中英

knex query with quotes around table name

I have a query as below which return user information where code is not null

select name,age from "dev.user" where code is not null

return expected output

in knex I am doing

knex("user").select('name','age').whereNotNull('code')

It return empty !

debug query return as follow

select "name", "age" from "user" where "code" is not null knex("dev.user").select('name','age').whereNotNull('code')

debug query return as follow

select "name", "age" from "dev"."user" where "code" is not null

First when I initialise knex I have set the schema which is not working second even if I provide schema it is generating query as "dev"."user" instead of "dev.user"

any pointers will be helpful

From the documentation, it looks like you should use .withSchema() . ( see link )

NOTE: identifier syntax has no place for selecting schema, so if you are doing schemaName.tableName, query might be rendered wrong. Use .withSchema('schemaName') instead.

Which would be:

knex("user")
   .withSchema("dev")
   .select('name','age').whereNotNull('code')

I haven't had to include a schema myself, so best of luck with this.

Gary.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM