pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Research on ?? operators
8+ messages / 4 participants
[nested] [flat]

* Research on ?? operators
@ 2019-06-04 09:00 Matteo Beccati <php@beccati.com>
  2019-06-04 10:38 ` Re: Research on ?? operators Andrew Gierth <andrew@tao11.riddles.org.uk>
  2019-06-04 10:49 ` Re: Research on ?? operators Steve Atkins <steve@blighty.com>
  0 siblings, 2 replies; 8+ messages in thread

From: Matteo Beccati @ 2019-06-04 09:00 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

Hello generals,

I'm trying to resurrect a change to the PHP PDO driver to allow using
the "?" json operator (and other operators containing a question mark),
without it being interpreted as a placeholder for a query argument. In
order to do so, like Hibernate, I went for the double "??" escaping:

https://wiki.php.net/rfc/pdo_escape_placeholders

One question that I'm supposed to answer now is: is there any known
usage in the wild of some custom "??" operator that would require funny
escaping like "????"?

I've tried to search pgxn but couldn't find any match, so I thought it
was worth to try and ask here.


Cheers
-- 
Matteo Beccati

Development & Consulting - http://www.beccati.com/





^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Research on ?? operators
  2019-06-04 09:00 Research on ?? operators Matteo Beccati <php@beccati.com>
@ 2019-06-04 10:38 ` Andrew Gierth <andrew@tao11.riddles.org.uk>
  2019-06-04 10:55   ` Re: Research on ?? operators Matteo Beccati <php@beccati.com>
  1 sibling, 1 reply; 8+ messages in thread

From: Andrew Gierth @ 2019-06-04 10:38 UTC (permalink / raw)
  To: Matteo Beccati <php@beccati.com>; +Cc: pgsql-general@lists.postgresql.org

>>>>> "Matteo" == Matteo Beccati <php@beccati.com> writes:

 Matteo> https://wiki.php.net/rfc/pdo_escape_placeholders

 Matteo> One question that I'm supposed to answer now is: is there any
 Matteo> known usage in the wild of some custom "??" operator that would
 Matteo> require funny escaping like "????"?

I don't recall seeing a ?? operator in the wild, but it is a perfectly
legal operator name and you should assume that it exists somewhere.

-- 
Andrew (irc:RhodiumToad)





^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Research on ?? operators
  2019-06-04 09:00 Research on ?? operators Matteo Beccati <php@beccati.com>
  2019-06-04 10:38 ` Re: Research on ?? operators Andrew Gierth <andrew@tao11.riddles.org.uk>
@ 2019-06-04 10:55   ` Matteo Beccati <php@beccati.com>
  0 siblings, 0 replies; 8+ messages in thread

From: Matteo Beccati @ 2019-06-04 10:55 UTC (permalink / raw)
  To: Andrew Gierth <andrew@tao11.riddles.org.uk>; +Cc: pgsql-general@lists.postgresql.org

Hi Andrew,

On 04/06/2019 12:38, Andrew Gierth wrote:
>>>>>> "Matteo" == Matteo Beccati <php@beccati.com> writes:
> 
>  Matteo> https://wiki.php.net/rfc/pdo_escape_placeholders
> 
>  Matteo> One question that I'm supposed to answer now is: is there any
>  Matteo> known usage in the wild of some custom "??" operator that would
>  Matteo> require funny escaping like "????"?
> 
> I don't recall seeing a ?? operator in the wild, but it is a perfectly
> legal operator name and you should assume that it exists somewhere.

Absolutely yes, that's why it is mentioned in my RFC and will be
eventually mentioned in the UPGRADE documentation.

But perhaps we can also safely assume that 99.9% of the users won't have
any operator containing "??", so it can be considered a minor BC-break.


Cheers
-- 
Matteo Beccati

Development & Consulting - http://www.beccati.com/





^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Research on ?? operators
  2019-06-04 09:00 Research on ?? operators Matteo Beccati <php@beccati.com>
@ 2019-06-04 10:49 ` Steve Atkins <steve@blighty.com>
  2019-06-04 11:01   ` Re: Research on ?? operators Matteo Beccati <php@beccati.com>
  1 sibling, 1 reply; 8+ messages in thread

From: Steve Atkins @ 2019-06-04 10:49 UTC (permalink / raw)
  To: PG mailing List <pgsql-general@lists.postgresql.org>



> On Jun 4, 2019, at 10:00 AM, Matteo Beccati <php@beccati.com> wrote:
> 
> Hello generals,
> 
> I'm trying to resurrect a change to the PHP PDO driver to allow using
> the "?" json operator (and other operators containing a question mark),
> without it being interpreted as a placeholder for a query argument. In
> order to do so, like Hibernate, I went for the double "??" escaping:
> 
> https://wiki.php.net/rfc/pdo_escape_placeholders
> 
> One question that I'm supposed to answer now is: is there any known
> usage in the wild of some custom "??" operator that would require funny
> escaping like "????"?

I don't know of one today, but that doesn't mean there isn't or won't
be tomorrow.

> I've tried to search pgxn but couldn't find any match, so I thought it
> was worth to try and ask here.

Doubling "?" to "??" isn't an obvious, intuitive way to do that, at least
to me. Maybe it would be to people coming from Java.

Perl's DBD::Pg deals with it in two ways. One is to allow escaping
the ? with a backslash - so "?" is a placeholder, while "\?" is passed as
"?" to the database. That's more consistent with other languages, and
I think you're far less likely to ever see a backslash in a custom operator
than "??".

The other is that it supports the postgresql standard placeholders - $1,
$2 etc. - which avoid the issue and are more flexible. It also has a configuration
option to completely ignore "?" in queries, so "$1" is a placeholder and "?"
is passed through to the database.

(Though I like the ":foo" or "@foo" style named placeholders best)

Cheers,
  Steve






^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Research on ?? operators
  2019-06-04 09:00 Research on ?? operators Matteo Beccati <php@beccati.com>
  2019-06-04 10:49 ` Re: Research on ?? operators Steve Atkins <steve@blighty.com>
@ 2019-06-04 11:01   ` Matteo Beccati <php@beccati.com>
  2019-06-04 12:35     ` Re: Research on ?? operators Michael Lewis <mlewis@entrata.com>
  0 siblings, 1 reply; 8+ messages in thread

From: Matteo Beccati @ 2019-06-04 11:01 UTC (permalink / raw)
  To: Steve Atkins <steve@blighty.com>; PG mailing List <pgsql-general@lists.postgresql.org>

Hi Steve,

On 04/06/2019 12:49, Steve Atkins wrote:
> Doubling "?" to "??" isn't an obvious, intuitive way to do that, at least
> to me. Maybe it would be to people coming from Java.

Funny enough, when I proposed \? on the pg mailing lists a few years ago
I was suggested ?? to match SQL escaping and Hibernate (going from memory).

> Perl's DBD::Pg deals with it in two ways. One is to allow escaping
> the ? with a backslash - so "?" is a placeholder, while "\?" is passed as
> "?" to the database. That's more consistent with other languages, and
> I think you're far less likely to ever see a backslash in a custom operator
> than "??".

That is true as well, but '\' being also the escape character for
strings would also lead to some WTF moments if one tried to escape the
backslash itself, e.g. '\\? === '\?'.

> The other is that it supports the postgresql standard placeholders - $1,
> $2 etc. - which avoid the issue and are more flexible. It also has a configuration
> option to completely ignore "?" in queries, so "$1" is a placeholder and "?"
> is passed through to the database.
> 
> (Though I like the ":foo" or "@foo" style named placeholders best)

PDO does support both positional "?" and ":foo" named placeholders.
Adding an option to disable one would probably break much more code and
libraries than just a simple escape character.


Cheers
-- 
Matteo Beccati

Development & Consulting - http://www.beccati.com/





^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Research on ?? operators
  2019-06-04 09:00 Research on ?? operators Matteo Beccati <php@beccati.com>
  2019-06-04 10:49 ` Re: Research on ?? operators Steve Atkins <steve@blighty.com>
  2019-06-04 11:01   ` Re: Research on ?? operators Matteo Beccati <php@beccati.com>
@ 2019-06-04 12:35     ` Michael Lewis <mlewis@entrata.com>
  2019-06-04 12:40       ` Re: Research on ?? operators Matteo Beccati <php@beccati.com>
  2019-06-04 12:44       ` Re: Research on ?? operators Steve Atkins <steve@blighty.com>
  0 siblings, 2 replies; 8+ messages in thread

From: Michael Lewis @ 2019-06-04 12:35 UTC (permalink / raw)
  To: Matteo Beccati <php@beccati.com>; +Cc: Steve Atkins <steve@blighty.com>; PG mailing List <pgsql-general@lists.postgresql.org>

*":foo" named placeholders*

If I may, is this supported natively in Postgres prepared statements? Can I
see an example? I do not care much for the numbers of positional
placeholders and would love to use names instead if possible.

^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Research on ?? operators
  2019-06-04 09:00 Research on ?? operators Matteo Beccati <php@beccati.com>
  2019-06-04 10:49 ` Re: Research on ?? operators Steve Atkins <steve@blighty.com>
  2019-06-04 11:01   ` Re: Research on ?? operators Matteo Beccati <php@beccati.com>
  2019-06-04 12:35     ` Re: Research on ?? operators Michael Lewis <mlewis@entrata.com>
@ 2019-06-04 12:40       ` Matteo Beccati <php@beccati.com>
  1 sibling, 0 replies; 8+ messages in thread

From: Matteo Beccati @ 2019-06-04 12:40 UTC (permalink / raw)
  To: Michael Lewis <mlewis@entrata.com>; +Cc: Steve Atkins <steve@blighty.com>; PG mailing List <pgsql-general@lists.postgresql.org>

Hi Michael,

On 04/06/2019 14:35, Michael Lewis wrote:
> /":foo" named placeholders/
> 
> If I may, is this supported natively in Postgres prepared statements?
> Can I see an example? I do not care much for the numbers of positional
> placeholders and would love to use names instead if possible.

Not natively. In this case it's the PHP PDO pgsql driver that performs
the translation.

I suppose many other DB libraries do that in any programming language.


Cheers
-- 
Matteo Beccati

Development & Consulting - http://www.beccati.com/





^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Research on ?? operators
  2019-06-04 09:00 Research on ?? operators Matteo Beccati <php@beccati.com>
  2019-06-04 10:49 ` Re: Research on ?? operators Steve Atkins <steve@blighty.com>
  2019-06-04 11:01   ` Re: Research on ?? operators Matteo Beccati <php@beccati.com>
  2019-06-04 12:35     ` Re: Research on ?? operators Michael Lewis <mlewis@entrata.com>
@ 2019-06-04 12:44       ` Steve Atkins <steve@blighty.com>
  1 sibling, 0 replies; 8+ messages in thread

From: Steve Atkins @ 2019-06-04 12:44 UTC (permalink / raw)
  To: PG mailing List <pgsql-general@lists.postgresql.org>



> On Jun 4, 2019, at 1:35 PM, Michael Lewis <mlewis@entrata.com> wrote:
> 
> ":foo" named placeholders
> 
> If I may, is this supported natively in Postgres prepared statements?

It's not. The only type we support are numbered $1 type placeholders.

> Can I see an example? I do not care much for the numbers of positional placeholders and would love to use names instead if possible.

It'd be nice. They're supported via rewriting at the driver level in some drivers, and I've written shims to convert them in an app a few times and it makes for much more readable - and bug-resistant - code.

Supporting it at the protocol level would be very nice.

Cheers,
  Steve




^ permalink  raw  reply  [nested|flat] 8+ messages in thread


end of thread, other threads:[~2019-06-04 12:44 UTC | newest]

Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-06-04 09:00 Research on ?? operators Matteo Beccati <php@beccati.com>
2019-06-04 10:38 ` Andrew Gierth <andrew@tao11.riddles.org.uk>
2019-06-04 10:55   ` Matteo Beccati <php@beccati.com>
2019-06-04 10:49 ` Steve Atkins <steve@blighty.com>
2019-06-04 11:01   ` Matteo Beccati <php@beccati.com>
2019-06-04 12:35     ` Michael Lewis <mlewis@entrata.com>
2019-06-04 12:40       ` Matteo Beccati <php@beccati.com>
2019-06-04 12:44       ` Steve Atkins <steve@blighty.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox