pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
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: Sun, 01 Aug 2021 13:23:13 -0400
Message-ID: <1456640.1627838593@sss.pgh.pa.us> (raw)
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>

I've been working through this patch, and trying to verify
compatibility against Oracle and DB2, and I see some points that need
discussion or at least recording for the archives.

* In Oracle, while the documentation for regexp_instr says that
return_option should only be 0 or 1, experimentation with sqlfiddle
shows that any nonzero value is silently treated as 1.  The patch
raises an error for other values, which I think is a good idea.
(IBM's docs say that DB2 raises an error too, though I can't test
that.)  We don't need to be bug-compatible to that extent.

* What should happen when the subexpression/capture group number of
regexp_instr or regexp_substr exceeds the number of parenthesized
subexpressions of the regexp?  Oracle silently returns a no-match
result (0 or NULL), as does this patch.  However, IBM's docs say
that DB2 raises an error.  I'm inclined to think that this is
likewise taking bug-compatibility too far, and that we should
raise an error like DB2.  There are clearly cases where throwing
an error would help debug a faulty call, while I'm less clear on
a use-case where not throwing an error would be useful.

* IBM's docs say that both regexp_count and regexp_like have
arguments "string, pattern [, start] [, flags]" --- that is,
each of start and flags can be independently specified or omitted.
The patch follows Oracle, which has no start option for 
regexp_like, and where you can't write flags for regexp_count
without writing start.  This is fine by me, because doing these
like DB2 would introduce the same which-argument-is-this issues
as we're being forced to cope with for regexp_replace.  I don't
think we need to accept ambiguity in these cases too.  But it's
worth memorializing this decision in the thread.

* The patch has most of these functions silently ignoring the 'g'
flag, but I think they should raise errors instead.  Oracle doesn't
accept a 'g' flag for these, so why should we?  The only case where
that logic doesn't hold is regexp_replace, because depending on which
syntax you use the 'g' flag might or might not be meaningful.  So
for regexp_replace, I'd vote for silently ignoring 'g' if the
occurrence-number parameter is given, while honoring it if not.

I've already made changes in my local copy per the last item,
but I've not done anything about throwing errors for out-of-range
subexpression numbers.  Anybody have an opinion about that one?

			regards, tom lane





view thread (28+ messages)  latest in thread

Message-ID: <1456640.1627838593@sss.pgh.pa.us>
Permalink:  ../1456640.1627838593@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/1456640.1627838593@sss.pgh.pa.us

 · 

reply

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: <1456640.1627838593@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> <1456640.1627838593@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