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
Additional double quotations in returning fields #2223
Comments
Can you confirm this exists in 42.2.23 ? |
Yes, I checked that in 42.2.23. |
So if memory serves me the reason we do this is to ensure that we can return "Number". Note the case. Postgres is unusual in that in order to return an identifier with mixed case it would have to be quoted. I'm not sure I have a solution for you that will not break more apps |
You are right about mixed case fields. |
On Thu, 5 Aug 2021 at 15:54, AmirHossein Najmi ***@***.***> wrote:
You are right about mixed case fields.
But I think the doAppendEscapedIdentifier() is doing anything Postgresql
needs for mixed case fields.
So why the returning field with extra double quotations can pass to this
method?(the method parameter should be "mixedCase" not ""mixedCase"".)
If you have a column FooBar and you do insert ... returning FooBar you will
get an error FooBar not found.
"FooBar" needs to be double quoted.
… —
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#2223 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AADDH5V7WUYRPYBH3NCGIBTT3LT6LANCNFSM5BUOAHIQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email>
.
|
The double quotes are intended to solve the following test=> create table t1 ("Id" serial primary key, name text);
|
Hi, we use an ORM called Ebean (https://github.com/ebean-orm/ebean) which has a configuration option to escape all identifiers. With this option enabled all table/column names will be double quoted by the ORM. We need this since some columns have names that we otherwise can not select, e.g. a column named "user". Now when we make an insert query the ORM calls JDBC API IMHO that is clearly a bug in PG JDBC, because the above is exactly the JDBC API call I would expect to do when I need to double quote column names. |
Seems that if it is already quoted we should probably not quote it. Care to provide a PR ? |
@davecramer Hm no, given that it is an utils method I would prefer if someone with better code knowledge fixes the issue. Personally I think it is only "easily" fixable if method Without that change the method can not decide wether or not the input in When applying the above behavior we have a breaking change for tables with columns that start/end with quotes. So if we have a table with column named However I think this change will result in better behavior since you can fix it in client code by calling Of maybe the fix needs to be done somewhere else and not in that particular method. But then the fix is likely to be more complex. |
basically that's the fix. If it starts with " and ends with " then do nothing. |
I think with the explanations that @jnehlmeier provided, the issue got more clear. Thank you so much. |
…xes Issue #2223 (#2224) * fix; do not add double quotes to identifiers already double quoted fixes Issue #2223 * add test case for quoted identifier * Added tests for mixed case columns in the returning clause * Add a property QUOTE_RETURNING_IDENTIFIERS which determines if we put double quotes around identifiers that are provided in the returning array. There are some ORMs that now quote all identifiers and if we in turn quote them this will cause an error. * update docs for quoteReturning * Remove unnecessary change * Unnecessary change
Closed by #2224 |
Describe the issue
When you are working with other JDBC implementations you need to use this format for of string for returning fields eg.: ""number"". (it means you had a string that includes a field name around by double quotations.)
inside the
Parser.addReturning()
method theUtils.escapeIdentifier()
is called and inside thatdoAppendEscapedIdentifier()
is called.In the body of
doAppendEscapedIdentifier()
, always is supposed that the returning field has not additional double quotations, and at the beginning and end of the method double quotations are added.So you need to remove any additional double quotation of returning field before passing it to doAppendEscapedIdentifier() and it could be done with something like this in
Parser.addReturning()
method:String columnName = returningColumnNames[col].replace("\"","");
For more info, I have faced this problem when I was working with Datanucleus JDO, which works with different JDBC implementations. and as I understood, the only implementation that has different behavior in this situation is PostgreSQL JDBC.
Driver Version?
42.1.4
Java Version?
openjdk version "11.0.11" 2021-04-20
OS Version?
Windows 10, 21H1
PostgreSQL Version?
13.3
To Reproduce
Steps to reproduce the behaviour:
Expected behaviour
Expected to remove additional double quotations in returning field before it getting passed to
Utils.escapeIdentifier()
Logs
("created_at","expires_at","last_used_at","modified_at","x","y","z","a","b") VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9)
RETURNING """number"""
2021-08-05 17:29:33.688 UTC [650] ERROR: column ""number"" does not exist at character 245
The text was updated successfully, but these errors were encountered: