From: Tom Lane <tgl@sss.pgh.pa.us>
To: mail@eduard-wulff.de
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #11211: regexp_matches acts like a WHERE
Date: Tue, 19 Aug 2014 18:20:03 -0400
Message-ID: <22166.1408486803@sss.pgh.pa.us> (raw)
In-Reply-To: <20140819130801.2534.30713@wrigleys.postgresql.org>
References: <20140819130801.2534.30713@wrigleys.postgresql.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, mail@eduard-wulff.de
Subject: Re: BUG #11211: regexp_matches acts like a WHERE
In-Reply-To: <22166.1408486803@sss.pgh.pa.us>
References: <20140819130801.2534.30713@wrigleys.postgresql.org> <22166.1408486803@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox