Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make quoting identifiers optional. #1761

Closed
ravshansbox opened this issue Oct 27, 2016 · 17 comments
Closed

Make quoting identifiers optional. #1761

ravshansbox opened this issue Oct 27, 2016 · 17 comments

Comments

@ravshansbox
Copy link

No description provided.

@elhigu
Copy link
Member

elhigu commented Oct 27, 2016

Any particular reason why this would be useful feature?

@ravshansbox
Copy link
Author

yes, specifically for oracle. In my case with oracle knex.raw('select * from table') works, but knew('table').select() doesn't work, because knex is generating query as select * from "table". AFAIK oracle is case insensitive for unquoted identifiers.

@elhigu
Copy link
Member

elhigu commented Oct 27, 2016

@atiertant any ideas if this is somehow possible with oracle or should people just write their code case-sensitive way?

@atiertant
Copy link
Contributor

@elhigu we should implement a fromRaw method

@elhigu
Copy link
Member

elhigu commented Oct 28, 2016

@atiertant I have no idea what you mean by fromRaw method :)

I was trying to ask if this is a good idea to support disabling identifier quoting on oracle or if there are better ways to get around the problem (e.g. some other global setting in database)? Would disabling quotes introduce any other potential problems?

@atiertant
Copy link
Contributor

@elhigu like whereRaw for where clause, you could use fromRaw to add raw in from clause, like this you could do:
knex.select('*').fromRaw('table')

@mxii
Copy link

mxii commented Nov 2, 2016

Would be great, would eliminate my problem with table-names including dots. They need to be escaped with quotes and this isn't possible with knex right now.

@ravshansbox
Copy link
Author

ravshansbox commented Nov 2, 2016

I'm not sure if fromRaw and whereRaw clauses are best options. How about unquoted column names? Maybe better to implement global option in configuration?

@elhigu
Copy link
Member

elhigu commented Nov 2, 2016

@ravshansbox I agree that fromRaw doesn't solve this problem at all. It would just add a shortcut for .from(knex.raw(...)) which is not nice either. I would say that if it will be implemented, it would be at first only for oracle dialect and instead of parsing + quoting the identifier it would just validate + use value without quotes to prevent SQL injection stuff.

We may continue this discussion if someone seriously considers implementing / testing / documenting this feature.

@atiertant
Copy link
Contributor

@elhigu @ravshansbox i'm not sure using unquoted column/table name is the best way too... but fromRaw would be at least in the knex spirit and could be useful for many other things...

@elhigu
Copy link
Member

elhigu commented Nov 2, 2016

@atiertant I'll add it as a separate issue, it is just a missing API which I didn't even knew didn't exist

@jtal
Copy link

jtal commented Dec 9, 2016

This a problem for Oracle users. It would be nice to optionally remove the quotes or force the case to upper (as Oracle does for table names).

If not, knex users who have Oracle need to change all of their scripts / queries to use quotes and if they use third party software (for example for reporting) they'll need to contact those companies to ask them to add quotes.

Is there anyone working on this in knex?

@elhigu
Copy link
Member

elhigu commented Dec 11, 2016

@jtal I don't believe that anyone is working on this. I fail to see the point how 3rd party software generated queries would require changes?

One can run queries like that already by using knex.raw('select * from NonQuotedTableName').

@atiertant
Copy link
Contributor

@elhigu @jtal we could add an option to make formater to not add quote but i'm sure there are many hardcoded quote in the code...

@sant123
Copy link

sant123 commented Feb 16, 2017

Hi, is there some advance to this issue? Thanks.

@elhigu
Copy link
Member

elhigu commented Sep 8, 2017

In next release you will be able to create custom quoting functionality #2084

@Gabriel-Aquino
Copy link

Gabriel-Aquino commented Apr 10, 2023

@elhigu like whereRaw for where clause, you could use fromRaw to add raw in from clause, like this you could do: knex.select('*').fromRaw('table')

Thanks bro! It works for me. I basically have used:

.select()
.fromRaw('myschema.mytable');

and query was wrote as: select * from myschema.mytable.

before it, i was using:
.select()
.from('myschema.mytable');

and query was: select * from "myschema"."mytable" and it was throwing an error.

Now it works. Thank you!!!

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

No branches or pull requests

7 participants