Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XK7c1-00010p-Uf for pgsql-bugs@arkaria.postgresql.org; Wed, 20 Aug 2014 15:15:46 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XK7c1-00033N-Cm for pgsql-bugs@arkaria.postgresql.org; Wed, 20 Aug 2014 15:15:45 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XK0q7-0001XX-7m for pgsql-bugs@postgresql.org; Wed, 20 Aug 2014 08:01:51 +0000 Received: from smtprelay06.ispgateway.de ([80.67.31.101]) by magus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1XK0q3-0006Xs-2u for pgsql-bugs@postgresql.org; Wed, 20 Aug 2014 08:01:50 +0000 Received: from [94.134.20.164] (helo=ewx230.localnet) by smtprelay06.ispgateway.de with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.68) (envelope-from ) id 1XK0q1-0006fe-1b; Wed, 20 Aug 2014 10:01:45 +0200 From: Eduard Wulff To: Tom Lane Cc: pgsql-bugs@postgresql.org Subject: Re: BUG #11211: regexp_matches acts like a WHERE Date: Wed, 20 Aug 2014 10:01:44 +0200 Message-ID: <7455174.3QXJZe6Vze@ewx230> User-Agent: KMail/4.13.3 (Linux/3.14-2-amd64; KDE/4.13.3; x86_64; ; ) In-Reply-To: <22166.1408486803@sss.pgh.pa.us> References: <20140819130801.2534.30713@wrigleys.postgresql.org> <22166.1408486803@sss.pgh.pa.us> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="ISO-8859-1" X-Df-Sender: MTAzNDU2Mg== X-Pg-Spam-Score: -0.8 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org Thanks Tom, your sql worked as I intended it - now I even read it in the documentation= =20 (9.7.3) as a "Tip". I expected a scalar NULL as you wrote. I did not grok the difference(?) between array and set. I even wondered abo= ut=20 my "syntax-solution" ()[n]. I am not the only one being on the wrong road: http://postgresql.1045698.n5.nabble.com/Using-regexp-matches-in-the-WHERE-c= lause-td5733684.html Regards, Eduard Am Dienstag, 19. August 2014, 18:20:03 schrieb Tom Lane: > mail@eduard-wulff.de writes: > > SELECT vorgangt.id, > >=20=20 > > (regexp_matches(vorgangt.text, '#\w{5,26}', 's'))[1] AS sernr, > >=20=20=20 > > regexp_replace(vorgangt.text, '\n', '=E2=81=8B', 'g') AS text_in_ei= ner_zeile > >=20=20 > > FROM vorgangt ORDER BY 1 > >=20 > > This works to get the first match if there is one. > >=20 > > BUT: it also _eliminates_ all rows that do not match from the result set >=20 > 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. >=20 > You could do it like this instead: >=20 > SELECT vorgangt.id, > (SELECT regexp_matches(vorgangt.text, '#\w{5,26}', 's'))[1] AS sernr, > regexp_replace(vorgangt.text, '\n', '=E2=81=8B', 'g') AS text_in_eine= r_zeile > FROM vorgangt ORDER BY 1 >=20 > Or you could wrap regexp_matches in a non-set-returning function. >=20 > regards, tom lane --=20 Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs