Re: Problems with question marks in operators (JDBC, ECPG, ...)

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Bruno Harbulot <bruno(at)distributedmatter(dot)net>
Cc: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, Kevin Grittner <kgrittn(at)ymail(dot)com>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Jan de Visser <jan(at)de-visser(dot)net>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Problems with question marks in operators (JDBC, ECPG, ...)
Date: 2015-05-20 16:46:02
Message-ID: CA+TgmoZT6KohEKQb3ocPRJ+u=QiGtYP2zmB0Ptf3FFcYd1aFyQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, May 19, 2015 at 5:34 PM, Bruno Harbulot
<bruno(at)distributedmatter(dot)net> wrote:
> Users of question mark operators are already admitting their application and
> code isn't portable (since they are specific to PostgreSQL and its
> extensions). The problem has more to do with how the other tools around
> handle these customisations. For example, it can be useful to have a model
> based on Hibernate in Java and be able to use ? operators for specific
> features. (Other tools like SQLAlchemy in Python also allow you to have
> customisations specific to the RDMBS platform, while being able to use the
> core features in a more platform-neutral way.)
>
> It turns out that you can indeed use ? in JSONB with a custom Hibernate
> query, you just need to double-escape it as follows: ? becomes ?? and has to
> be escaped as \?\?, but \ has to be escaped itself...
>
> SQLQuery query = session
> .createSQLQuery("SELECT
> CAST((CAST('{\"key1\":123,\"key2\":\"Hello\"}' AS jsonb) \\?\\? CAST(? AS
> text)) AS BOOLEAN)");
> query.setString(0, "key1");

I think we should be more focused on this part of the issue. It seems
to me that it's a good idea for connectors to have an escaping
mechanism. Pretty much any syntax that supports funny characters that
do magical things should also have a way to turn the magic off when
it's not wanted. But it's not a bad thing either for the core project
to try to steer around operator names that are likely to require
frequent use of that escaping mechanism.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Heikki Linnakangas 2015-05-20 16:49:29 Re: Typo patch
Previous Message Thom Brown 2015-05-20 16:44:05 Re: INSERT ... ON CONFLICT UPDATE/IGNORE 4.0