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
[PostgreSQL]PostgreSQL client should recognize ? placemarkers #509
Comments
There is no standard. |
Agreed that out of the box we should stick with original DB syntax. I would like however to support named place holders for simple mapping (i.e |
Folks, I would still very much like to see this. We really have to jump through hoops in Hibernate Reactive to accommodate this. I didn't want to push the issue too hard earlier, since, well, HR was still in a very experimental stage. But do still I think it's a really pretty basic feature of a client API to abstract over differences in the parameter-binding syntax of the various supported databases.
That's simply not true. JDBC and ODBC are almost-universally-supported standards. It's in our very-strong interest to make it easy for people to take SQL they wrote for execution via JDBC, and have it work without change on Vert.x. |
This proved out to be a slight inconvenience for me when exploring the option to run jOOQ generated sql against the vertx-pg-client. They seem to only support jdbc style or named bindings out of the box (https://www.jooq.org/doc/latest/manual/sql-building/bind-values/) |
JDBC and ODBC are almost-universally-supported standards in Java not strongly against it, but just giving some perspective |
it is not clear what is needed from HRX perspective, do you mean that HRX will generate queries with placeholder and then the client will parse it to replace the placeholders by the native placeholders or do you mean more ? If that's the former we can easily do it by providing some kind of query builder that will generate a portable string accross vendor, i.e something like If that's the later it is more difficult to achieve and might lead to parse each database syntax which is not a goal of this project, i.e https://github.com/pgjdbc/pgjdbc/blob/161ea24965b3d11067f96b9765cda10f8b59e08b/pgjdbc/src/main/java/org/postgresql/core/Parser.java#L45 unless we provide a syntax that does not require to parse SQL |
Right, that.
No that doesn't help because it's not HR generating the SQL. We're just taking SQL that Hibernate generates and doing this same replacement ourselves. And of course we can do that (are doing it, in fact). But see the thing is, that it's not just HR that needs to do this: it's anyone who wants to use any sort of pre-existing SQL-generation lib written for Java together with the You would save uses a lot of pain by just centralizing that code in each of the Vert.x drivers.
Right, but right now you're forcing lots of clients to do that reparsing for you. And they're probably going to do a worse job of it. But let me make a small correction here: you definitely don't need to parse anything. You merely need to tokenize the incoming SQL, which a task that really is very straightforward. Building a parser for SQL is quite a task; building a tokenizer for SQL is pretty trivial. |
No, not just in Java! ODBC is supported across multiple languages. And JDBC is just a Java clone of it. |
you are saying that a simple tokenization of a query with |
What in particular in that thread are you referring to? I'm not asking you to support the ODBC/JDBC escape syntax, since that is really quite complex, with lots of standard functions to translate to database native functions, and not even JDBC drivers do a good job of supporting it. All I'm asking for is the query parameter syntax. |
It is not clear to me actually what you are asking to support. Are you asking that the PostgreSQL client is able support rewriting queries using |
Yes. But the tokenization is not quite that trivial since you need to avoid doing replacement inside comments, quoted identifiers, and literal strings. |
And the point is that I want to call some method where that just happens automatically if it is the Postgres client, without having to ask myself what client it is. |
Just for better understand the problem. HRX generates SQL from java code/classes, and the generated code is aware of the target database (for type support, sequences, etc). So what is blocking HRX to generate the SQL with the target specific marker? IMHO this looks like asking for a change on the wrong side of the problem. I have the feeling this would be wasting a few CPU cycles as time was spent on generating SQL on HRX then the client, needs to rewrite the generated SQL to adhere to the server. Sorry for not adding anything to the thread, but just expressing my opinion. |
No, HR doesn't generate SQL. Hibernate ORM generates SQL. And, like essentially every other library that generates SQL in the entire Java ecosystem, it generates SQL with Now, there are two choices here. Either:
I really don't quite comprehend the resistance to this. It's a relatively-trivial function that just makes the Vert.x database drivers work the same way as every JDBC and ODBC driver across multiple languages and all SQL databases. It's totally the norm for database drivers to do this. |
In fact this is the path we tried to go down, and after a lot of suffering, we essentially failed to make it work. You see, there are lots of places in Hibernate ORM which render SQL, and sometimes different "fragments" are rendered in different places, and then there are a few other places where already-rendered SQL (or hand-written SQL passed by the user) is subsequently manipulated in some way (to add limits, filters, etc). And all these different bits need to be aware of each other in order to generate the right parameter numbers and not wind up with (To be clear, what makes this problem painful isn't So anyway, now I've just given up on this and I've decided to rip out all that code and just post-process the SQL and replace the |
So to clear things up a bit, here's the implementation I'm currently using. I'm sure it can be improved. Perhaps it's going to exhibit better performance by working directly with bytes instead of codepoints, for example, and I know it should support Postgres But it's really not that much of a scary thing, it seems to me. |
@gavinking yes I see what you mean, I think we can do such API but keep it internal (i.e on |
I think we could have a tag on |
Well then there's barely any value in having it in Vert.x rather than in HR, since the whole point of why I'm asking for this is that I think other people will want to use it. I find it difficult to believe that we're the only ones who're going to run into this.
Ideally from my point of view it would be a setting on |
@jrno jOOQ supports all bind parameter syntaxes:
Example for PostgreSQL:
Output:
In general the database abstraction or code generator (jOOQ, hibernate, JDBC) should output the database specific syntax. There should be not need for a plain database driver to tokenize the SQL for syntax convertion. vertx-sql-client is a plain database driver, not a JDBC driver with database abstraction. |
@gavinking Hibernate System Requirements:
vertx-sql-client/vertx-pg-client is not a JDBC driver. hibernate-orm has |
In my case the SQL is written by humans. So my proposal would be to have two functions, one that converts JDBC placeholders to native placeholders and another that converts named placeholders to native placeholders. I'm quite happy to work on creating these functions, but I can only test against MS, My & Postgres. |
Postgres' $1, $2, etc, is nonstandard, AFAIK, and contrary to ODBC and JDBC.
We should at least have the option to use this syntax if we want to.
Issue reported in smallrye/smallrye-mutiny-vertx-bindings#106
The text was updated successfully, but these errors were encountered: