pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #11211: regexp_matches acts like a WHERE
3+ messages / 3 participants
[nested] [flat]

* BUG #11211: regexp_matches acts like a WHERE
@ 2014-08-19 13:08  mail@eduard-wulff.de
  0 siblings, 1 reply; 3+ messages in thread

From: mail@eduard-wulff.de @ 2014-08-19 13:08 UTC (permalink / raw)
  To: pgsql-bugs

The following bug has been logged on the website:

Bug reference:      11211
Logged by:          Eduard Wulff
Email address:      mail@eduard-wulff.de
PostgreSQL version: 9.4beta2
Operating system:   Debian testing AMD64
Description:        

 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

EXPECTED: return NULL or at least an empty string if there is no match


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #11211: regexp_matches acts like a WHERE
@ 2014-08-19 22:20  Tom Lane <tgl@sss.pgh.pa.us>
  parent: mail@eduard-wulff.de
  0 siblings, 1 reply; 3+ messages in thread

From: Tom Lane @ 2014-08-19 22:20 UTC (permalink / raw)
  To: mail@eduard-wulff.de; +Cc: 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


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #11211: regexp_matches acts like a WHERE
@ 2014-08-20 08:01  Eduard Wulff <mail@eduard-wulff.de>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 3+ messages in thread

From: Eduard Wulff @ 2014-08-20 08:01 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-bugs

Thanks Tom,

your sql worked as I intended it - now I even read it in the documentation 
(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 about 
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-clause-td5733684.html

Regards,

Eduard


Am Dienstag, 19. August 2014, 18:20:03 schrieb Tom Lane:
> 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



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2014-08-20 08:01 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2014-08-19 13:08 BUG #11211: regexp_matches acts like a WHERE mail@eduard-wulff.de
2014-08-19 22:20 ` Tom Lane <tgl@sss.pgh.pa.us>
2014-08-20 08:01   ` Eduard Wulff <mail@eduard-wulff.de>

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