RES: Trouble with regexp_matches - Mailing list pgsql-general

From Edson Richter
Subject RES: Trouble with regexp_matches
Date
Msg-id CY1PR01MB1818E86AEB69B18A31BBCF01CFA50@CY1PR01MB1818.prod.exchangelabs.com
Whole thread Raw
In response to Re: Trouble with regexp_matches  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
> -----Mensagem original-----
> De: Tom Lane [mailto:tgl@sss.pgh.pa.us]
> Enviada em: sábado, 5 de novembro de 2016 15:21
> Para: Edson Richter <edsonrichter@hotmail.com>
> Cc: pgsql-general@postgresql.org
> Assunto: Re: [GENERAL] Trouble with regexp_matches
> 
> Edson Richter <edsonrichter@hotmail.com> writes:
> > I’m running the query below, and it is limiting results as if
> “regexp_matches” being in where clause.
> > IMHO, it is wrong: in case there is no match, shall return null or empty array
> – not remove the result from the set!!!
> 
> Well, no, because regexp_matches() returns a set.  If there's no match,
> there's zero rows in the set.

For me, it is a strange behavior - putting something in select clause will restrict results as if it lies in join or
whereclauses.
 


> 
> The standard workaround is to use a scalar sub-select, which has the effect
> of converting a zero-row result into a NULL:
> 
> select codigoocorrencia, datahoraocorrencia, datahoraimportacao,
>        observacao, (select regexp_matches(observacao, '\d\d/\d\d/\d\d\d\d'))
> from ...
> 
> As of v10 there will be a less confusing solution: use regexp_match() instead.
> 
>             regards, tom lane

Ok, for now, I've changed regexp_matches() to "... substring(observacao from '\d\d/\d\d/\d\d\d\d')" which does the job
gracefully.

I still believe that an alert shall be made in the docs page (String functions), because seems confusing and error
prone.


Thanks,

Edson Richter



pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Trouble with regexp_matches
Next
From: Edson Richter
Date:
Subject: RES: Trouble with regexp_matches