regexp_replace( , , , NULL ) returns null?

Started by Jim Nasbyover 11 years ago3 messages
#1Jim Nasby
jnasby@enova.com

Is there any particular reason for this:

decibel@decina.local=# SELECT regexp_replace( 'a', 'a', 'b', null ) IS NULL;
?column?
----------
t
(1 row)

ISTM it’d be a lot better if it treated NULL flags the same as ‘’...
--
Jim Nasby, Lead Data Architect (512) 569-9461

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Jim Nasby (#1)
Re: regexp_replace( , , , NULL ) returns null?

Jim Nasby <jnasby@enova.com> writes:

Is there any particular reason for this:
decibel@decina.local=# SELECT regexp_replace( 'a', 'a', 'b', null ) IS NULL;
?column?
----------
t
(1 row)

Yeah: regexp_replace is strict.

ISTM it�d be a lot better if it treated NULL flags the same as ��...

In Oracle's universe that probably makes sense, but to me it's not
sensible. Why should "unknown" flags produce a non-unknown result?

I find it hard to envision many use-cases where you wouldn't actually
have the flags as a constant, anyway; they're too fundamental to the
behavior of the function.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#3Jim Nasby
jnasby@enova.com
In reply to: Tom Lane (#2)
Re: regexp_replace( , , , NULL ) returns null?

On 5/2/14, 8:57 PM, Tom Lane wrote:

Jim Nasby <jnasby@enova.com> writes:

ISTM it�d be a lot better if it treated NULL flags the same as ��...

In Oracle's universe that probably makes sense, but to me it's not
sensible. Why should "unknown" flags produce a non-unknown result?

Only because they're more options than data.

I find it hard to envision many use-cases where you wouldn't actually
have the flags as a constant, anyway; they're too fundamental to the
behavior of the function.

Unless you're wrapping this function; handling the case of the flags being optional becomes easier then.

(FWIW, I'm creating a version that accepts an array of search/replace arguments.)
--
Jim Nasby, Lead Data Architect (512) 569-9461

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers