-
Notifications
You must be signed in to change notification settings - Fork 176
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
Escape characters are mishandled in the LIKE clause on PostgreSQL #2324
Comments
Hi @rfelcman , SELECT TOTAL FROM ORDERS WHERE PURCHASEDBY LIKE ? ORDER BY TOTAL the following log entry appears before any custom logic in
Since the SQL is logged before reaching the platform-specific handling, any changes made inside |
@rfelcman Different results are obtained when we use different databases.
which corresponds to the row with For DBs which treats '\' as normal character by default (DB2, Oracle DB, etc) the result obtained is
which corresponds to the row with |
Current Behavior
When persisting an entity to a PostgreSQL database EclipseLink
with a column that contains a string with the backslash character ()
the data is correctly inserted into the table.
For example, using the following entity:
Executing the following persist methods:
Results in the following table in PostgreSQL
Later when attempting to execute the a query with a LIKE clause:
Eclipselink attempts to execute the following SQL query:
Which returns the result:
[23.93000030517578]
Because PostgreSQL will always escape backslash characters in a LIKE clause by default.
As described in their documentation here: https://www.postgresql.org/docs/7.1/functions-matching.html
To match a literal underscore or percent sign without matching other characters, the respective character in pattern must be preceded by the escape character. The default escape character is the backslash but a different one may be selected by using the ESCAPE clause. To match the escape character itself, write two escape characters.
NOTE: The PostgreSQL setting standard_conforming_strings=on affects the default behavior of backslash in other areas, but never within a LIKE clause.
Expected behavior
I would expect EclipseLink to modify the input parameter for any LIKE clause to escape any backslashes.
Which would result in the following SQLQuery:
The text was updated successfully, but these errors were encountered: