Re: BUG #11211: regexp_matches acts like a WHERE

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: BUG #11211: regexp_matches acts like a WHERE
Дата
Msg-id 22166.1408486803@sss.pgh.pa.us
обсуждение исходный текст
Ответ на BUG #11211: regexp_matches acts like a WHERE  (mail@eduard-wulff.de)
Ответы Re: BUG #11211: regexp_matches acts like a WHERE  (Eduard Wulff <mail@eduard-wulff.de>)
Список 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 по дате отправления:

Предыдущее
От: rqmedes@gmail.com
Дата:
Сообщение: BUG #11210: Limit on Query causes error or no JSON labels in output
Следующее
От: Tom Lane
Дата:
Сообщение: Re: BUG #11207: empty path will segfault jsonb #>