Postgres uses ? as an operator; may its JDBC driver allow escaping?

Mark Rotteveel mark at lawinegevaar.nl
Mon Feb 11 12:44:11 PST 2013


On 11-2-2013 21:11, Lance Andersen - Oracle wrote:
> There is nothing in the SQL standard that would support the use of an '?' as anything but a parameter marker.  While you may be able to make this work with just a Statement object, when you get to a PreparedStatement, I am not sure how you will be able to support  this as an operator as there is no way in the SQL standard to escape the '?'  as a parameter marker.

I believe the question of Seamus is more: 'Would the JDBC spec allow us 
to treat a question mark in a query string as anything other than a 
parameter placeholder?' and alternatively: 'If it isn't allowed by the 
JDBC spec, in what way can we escape it?'

Lets be practical: the SQL standard defines a lot of things that don't 
match with reality, and PostgreSQL does actually have the ? as an 
operator which currently isn't supported by their JDBC driver. 
PostgreSQL itself - AFAIK - doesn't actually use the ? as the parameter 
placeholder, so their JDBC driver needs to do the parsing and replacing 
question marks with the actual placeholders.

I think supporting the ? operator directly might be possible (if JDBC 
allows that), but I guess that would really complicate their parser 
(because you will need to a lot more context and state to get it right).

So escaping or an alternative operator would be better. To be a bit like 
the JDBC defined escapes you could think about {ve ?} or {ve "?"} (ve 
for vendor escape, just made it up). For an alternative operator I think 
an escape would be preferable to make it clear it is not in the actual 
PostgreSQL language (say: {qm} or {ve qm} (qm for questionmark)).

Mark
-- 
Mark Rotteveel


More information about the jdbc-spec-discuss mailing list