Re: BUG #11211: regexp_matches acts like a WHERE - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #11211: regexp_matches acts like a WHERE
Date
Msg-id 22166.1408486803@sss.pgh.pa.us
Whole thread Raw
In response to BUG #11211: regexp_matches acts like a WHERE  (mail@eduard-wulff.de)
Responses Re: BUG #11211: regexp_matches acts like a WHERE
List pgsql-bugs
mail@eduard-wulff.de writes:
>  SELECT vorgangt.id,
>   (regexp_matches(vorgangt.text, '#\w{5,26}', 's'))[1] AS sernr,
>     regexp_replace(vorgangt.text, '\n', '⁋', 'g') AS text_in_einer_zeile
>  FROM vorgangt ORDER BY 1

> This works to get the first match if there is one.

> BUT: it also _eliminates_ all rows that do not match from the result set

I see no bug here.  You've got a set-returning function in the target
list, and when it returns zero rows, you get zero rows (from that source
row).  You seem to wish it would return a scalar NULL for no match,
but that's not how the function is defined.

You could do it like this instead:

 SELECT vorgangt.id,
  (SELECT regexp_matches(vorgangt.text, '#\w{5,26}', 's'))[1] AS sernr,
    regexp_replace(vorgangt.text, '\n', '⁋', 'g') AS text_in_einer_zeile
 FROM vorgangt ORDER BY 1

Or you could wrap regexp_matches in a non-set-returning function.

            regards, tom lane

pgsql-bugs by date:

Previous
From: rqmedes@gmail.com
Date:
Subject: BUG #11210: Limit on Query causes error or no JSON labels in output
Next
From: Tom Lane
Date:
Subject: Re: BUG #11207: empty path will segfault jsonb #>