Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XJrlN-0008U2-8v for pgsql-bugs@arkaria.postgresql.org; Tue, 19 Aug 2014 22:20:21 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XJrlL-0001wc-Ei for pgsql-bugs@arkaria.postgresql.org; Tue, 19 Aug 2014 22:20:19 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XJrlD-0001hU-Sb for pgsql-bugs@postgresql.org; Tue, 19 Aug 2014 22:20:12 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XJrl8-0007Gh-ME for pgsql-bugs@postgresql.org; Tue, 19 Aug 2014 22:20:07 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id s7JMK3md022167; Tue, 19 Aug 2014 18:20:03 -0400 From: Tom Lane To: mail@eduard-wulff.de cc: pgsql-bugs@postgresql.org Subject: Re: BUG #11211: regexp_matches acts like a WHERE In-reply-to: <20140819130801.2534.30713@wrigleys.postgresql.org> References: <20140819130801.2534.30713@wrigleys.postgresql.org> Comments: In-reply-to mail@eduard-wulff.de message dated "Tue, 19 Aug 2014 13:08:01 -0000" Date: Tue, 19 Aug 2014 18:20:03 -0400 Message-ID: <22166.1408486803@sss.pgh.pa.us> X-Pg-Spam-Score: -2.6 (--) 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 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