maybe incorrect regexp_replace behavior in v8.3.4 ?

Started by Gauthier, Davealmost 14 years ago3 messagesgeneral
Jump to latest
#1Gauthier, Dave
dave.gauthier@intel.com

Hi:

bi_hsx_a0_latest=# select regexp_replace('xxx','^xxx$','abc');
regexp_replace
----------------
abc
(1 row)
expected behavior because there's a match

bi_hsx_a0_latest=# select regexp_replace('xxx','^xxxy$','abc');
regexp_replace
----------------
xxx
(1 row)
expected because there is no match (the 'y' in 'xxxy')

bi_hsx_a0_latest=# select regexp_replace('xxx','^xxxy$',null);
regexp_replace
----------------

(1 row)
But why did it return null in this case? I would think no match would leave it 'xxx'.

Thanks in Advance for any help and/or explanation.

#2Richard Huxton
dev@archonet.com
In reply to: Gauthier, Dave (#1)
Re: maybe incorrect regexp_replace behavior in v8.3.4 ?

On 16/05/12 14:54, Gauthier, Dave wrote:

bi_hsx_a0_latest=# select regexp_replace('xxx','^xxxy$',null);
regexp_replace
----------------

(1 row)
But why did it return null in this case? I would think no match would leave it 'xxx'.

If a function is defined as "strict" then any null parameters
automatically result in a null result.

And indeed, this:
SELECT * FROM pg_proc WHERE proname LIKE 'regexp_r%';
shows pro_isstrict is set to true, as it is for most other function.s

--
Richard Huxton
Archonet Ltd

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Gauthier, Dave (#1)
Re: maybe incorrect regexp_replace behavior in v8.3.4 ?

"Gauthier, Dave" <dave.gauthier@intel.com> writes:

bi_hsx_a0_latest=# select regexp_replace('xxx','^xxxy$',null);
regexp_replace
----------------

(1 row)
But why did it return null in this case?

regexp_replace is strict, so it never even gets called when there's
a null input.

regards, tom lane