add ?-contained operator support#187
add ?-contained operator support#187tminglei wants to merge 4 commits intopgjdbc:masterfrom tminglei:master
Conversation
|
Any feedback? |
|
I'm not crazy about duplicating the ? here, but what alternatives do we have? |
|
@davecramer that's also what I want to know. |
|
The better but more invasive option is to have a libpq compatibility mode I don't believe it is possible to smartly interpret/parse a question mark I'd prefer "?" to "??" And explain it to mean that the question mark is David J. On Saturday, October 25, 2014, Dave Cramer notifications@github.com wrote:
|
|
What about some variant of the existing JDBC escape syntax? "col {xxx ?} ?" where xxx is some keyword to indicate that the result should be copied into the resulting sql literally. |
|
I can imagine someone wanting to turn off jdbc escape processing but still Besides, using the standard syntax for a non-standard feature could be I'd consider making it so that you have to turn jdbc escape processing off David J. On Saturday, October 25, 2014, Kris Jurka notifications@github.com wrote:
|
|
After some thinking ?? is probably the simplest. Anything else seems worse. Dave Cramer On 25 October 2014 22:19, 涂名雷 notifications@github.com wrote:
|
|
It could have a BC impact if someone was using the v2 protocol and set two parameters, so that ... but really, that's a don't do that kind of situation. I don't think it'll have any other BC impact, and it's pretty simple and easy to understand. |
|
Edit: I see the logic in sql-esque escaping by doubling; Craig's comment did not come through completely in e-mail so I missed the reasoning. Dave & Craig: Care to elaborate on why ? would be worse than ?? ? David J. On Sun, Oct 26, 2014 at 2:05 AM, Dave Cramer notifications@github.com
|
|
On 10/29/2014 08:02 AM, David Johnston wrote:
My main reason for that preference is that ?? is more consistent with I don't think it's significantly different from a BC PoV; writing ? in Craig Ringer http://www.2ndQuadrant.com/ |
|
The reason I like the escape clause as opposed to these other suggestions is that you can write the same code for both prepared and non-prepared usage. I think it is awkward to have to use different syntax for identical queries executed by different methods. @tminglei yes, the escape processing currently wouldn't work because it does the full replace processing before looking for parameters, but that is not required. You could do escape processing which returned an object which had knowledge of the escaped constructs so that parameter detection would skip over them. |
|
No, wait. I see people are suggesting to do this escaping for all ?? even in plain (unprepared) sql. That might be OK, but the danger @ringerc notes isn't just ?? for two parameters, but an operator named ?? for unprepared code, right? |
|
@kjurka - didn't even consider non-prepared...and yes escaping there would be problematic since the ?? sequence can be a valid within an operator. "?" exhibits the same problem :( Are there currently any PostgreSQL features (thinking dollar quoting though it may no longer be a problem) that doesn't play well with JDBC escaping such that people would want to use this feature without having to allow all JDBC escape sequences? I do think having non-parameterized queries able to be executed by either statement or preparedstatement is something that is a worse case option. |
|
On 10/29/2014 08:18 AM, Kris Jurka wrote:
Oh, good point. That tips it in favour of the JDBC escape syntax for me, despite how Rather than using an escape for ? I'd want to have a more general way to Craig Ringer http://www.2ndQuadrant.com/ |
|
Dave Cramer On 28 October 2014 20:42, Craig Ringer notifications@github.com wrote:
|
|
If you rebase this on top of git head and squash away the reverted commit, I'll merge the updated pull request. You're working on top of a local branch named Assuming your local working branch is called
Then fetch pgjdbc master:
and rebase on top of it:
then squash away your unintended changes with an interactive rebase:
and after testing, push the reworked branch, retaining the upstream branch name
In case of issues, you can abort any open rebase and reset to the before rebase state:
|
|
Hi @ringerc can I create a new branch on local, based on pgjdbc/pgjdbc, then redo the changes, then send a new PR again? It seems easier to me. |
|
Sure, if that's easier for you, no problem. Sorry for the hassle, it's just that a lot has changed recently. I'd probably just merge anyway, but I don't want the noise of the deleted commit in the final history. |
Currently it seems PgJDBC didn't support ?-contained operator escaping, which lead to some ?-contained operators, such as hstore's
?&/?|and ltree's?/?~/?@and so on, can't be used in PreparedStatement.This pull request try to resolve the problem.
How to use it?
double mark the
?when passing a raw sql to connection's prepareStatement method, as below:and PgJDBC won't recognize the
??as a parameter placeholder, and restore it back to?before sending to postgres server.Pls help review and give your concerns or suggestions. Thanks!