From: Tom Lane <tgl@sss.pgh.pa.us>
To: Gilles Darold <gilles@darold.net>
Cc: Gilles Darold <gillesdarold@gmail.com>
Cc: Chapman Flack <chap@anastigmatix.net>
Cc: er@xs4all.nl
Cc: pgsql-hackers@lists.postgresql.org
Subject: Re: [PATCH] proposal for regexp_count, regexp_instr, regexp_substr and regexp_replace
Date: Fri, 30 Jul 2021 17:38:24 -0400
Message-ID: <1124806.1627681104@sss.pgh.pa.us> (raw)
In-Reply-To: <2204c4a4-8ee8-abdd-d5ca-d0b6893f96ab@darold.net>
References: <fc160ee0-c843-b024-29bb-97b5da61971f@darold.net>
<2292303d-766d-2172-2942-b076a3bb6505@darold.net>
<2122577845.234888.1616324857283@webmailclassic.xs4all.nl>
<9f91e4e7-19c8-d8e0-6955-fefaebd4c8fe@darold.net>
<60575B5A.4080807@anastigmatix.net>
<345476.1616338397@sss.pgh.pa.us>
<45fe2893-1efc-1666-3ea5-b5fb1918c7fa@gmail.com>
<212635.1627329361@sss.pgh.pa.us>
<2204c4a4-8ee8-abdd-d5ca-d0b6893f96ab@darold.net>
Gilles Darold <gilles@darold.net> writes:
> Le 26/07/2021 à 21:56, Tom Lane a écrit :
>> I'm inclined to just drop the regexp_replace additions. I don't think
>> that the extra parameters Oracle provides here are especially useful.
>> They're definitely not useful enough to justify creating compatibility
>> hazards for.
> I would not say that being able to replace the Nth occurrence of a
> pattern matching is not useful but i agree that this is not a common
> case with replacement. Both Oracle [1] and IBM DB2 [2] propose this form
> and I have though that we can not have compatibility issues because of
> the different data type at the 4th parameter.
Well, here's an example of the potential issues:
regression=# create function rr(text,text,text,text) returns text
regression-# language sql as $$select 'text'$$;
CREATE FUNCTION
regression=# create function rr(text,text,text,int4) returns text
language sql as $$select 'int4'$$;
CREATE FUNCTION
regression=# select rr('a','b','c','d');
rr
------
text
(1 row)
regression=# select rr('a','b','c',42);
rr
------
int4
(1 row)
So far so good, but:
regression=# prepare rr as select rr('a','b','c',$1);
PREPARE
regression=# execute rr(12);
rr
------
text
(1 row)
So somebody trying to use the 4-parameter Oracle form from, say, JDBC
would get bit if they were sloppy about specifying parameter types.
The one saving grace is that digits aren't valid regexp flags,
so the outcome would be something like
regression=# select regexp_replace('a','b','c','12');
ERROR: invalid regular expression option: "1"
which'd be less difficult to debug than silent misbehavior.
Conversely, if you thought you were passing flags but it somehow
got interpreted as a start position, that would fail too:
regression=# prepare rri as select rr('a','b','c', $1::int);
PREPARE
regression=# execute rri('gi');
ERROR: invalid input syntax for type integer: "gi"
LINE 1: execute rri('gi');
^
Still, I bet a lot that we'd see periodic bug reports complaining
that it doesn't work.
> Anyway, maybe we can just
> rename the function even if I would prefer that regexp_replace() be
> extended. For example:
> regexp_replace(source, pattern, replacement [, flags ]);
> regexp_substitute(source, pattern, replacement [, position ] [,
> occurrence ] [, flags ]);
Hmm. Of course the entire selling point of this patch seems to be
bug-compatibility with Oracle, so using different names is largely
defeating the point :-(
Maybe we should just hold our noses and do it. The point that
you'd get a recognizable failure if the wrong function were chosen
reassures me a little bit. We've seen a lot of cases where this
sort of ambiguity results in the system just silently doing something
different from what you expected, and I was afraid that that could
happen here.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: tgl@sss.pgh.pa.us, gilles@darold.net, gillesdarold@gmail.com, chap@anastigmatix.net, er@xs4all.nl
Subject: Re: [PATCH] proposal for regexp_count, regexp_instr, regexp_substr and regexp_replace
In-Reply-To: <1124806.1627681104@sss.pgh.pa.us>
References: <fc160ee0-c843-b024-29bb-97b5da61971f@darold.net> <2292303d-766d-2172-2942-b076a3bb6505@darold.net> <2122577845.234888.1616324857283@webmailclassic.xs4all.nl> <9f91e4e7-19c8-d8e0-6955-fefaebd4c8fe@darold.net> <60575B5A.4080807@anastigmatix.net> <345476.1616338397@sss.pgh.pa.us> <45fe2893-1efc-1666-3ea5-b5fb1918c7fa@gmail.com> <212635.1627329361@sss.pgh.pa.us> <2204c4a4-8ee8-abdd-d5ca-d0b6893f96ab@darold.net> <1124806.1627681104@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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