pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
replace_matches does not return {null}
2+ messages / 2 participants
[nested] [flat]

* replace_matches does not return {null}
@ 2011-02-22 11:25  Andreas Gaab <A.Gaab@scanlab.de>
  0 siblings, 1 reply; 2+ messages in thread

From: Andreas Gaab @ 2011-02-22 11:25 UTC (permalink / raw)
  To: pgsql-sql

Hi,

I tried to order a text-column only by parts of the entries. Therefore I used regexp_matches(), but unfortunately I am loosing rows.

SELECT regexp_matches('abc','[0-9]+'),  regexp_matches('123','[0-9]+');

Does not return "{null}, {123}" but no result at all.

Is this behavior expected? How can I work around?

I am running postgres 8.4


Andreas


___________________________________________________________________________

SCANLAB AG
Dr. Andreas Simon Gaab
Entwicklung * R & D

Siemensstr. 2a * 82178 Puchheim * Germany
Tel. +49 (89) 800 746-513 * Fax +49 (89) 800 746-199
mailto:a.gaab@scanlab.de * www.scanlab.de<http://www.scanlab.de;

Amtsgericht München: HRB 124707 * USt-IdNr.: DE 129 456 351
Vorstand: Georg Hofner (Sprecher), Christian Huttenloher, Norbert Petschik
Aufsichtsrat (Vorsitz): Dr. Hans J. Langer
___________________________________________________________________________

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

* Re: replace_matches does not return {null}
@ 2011-02-22 16:39  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Andreas Gaab <A.Gaab@scanlab.de>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2011-02-22 16:39 UTC (permalink / raw)
  To: Andreas Gaab <A.Gaab@scanlab.de>; +Cc: pgsql-sql

Andreas Gaab <A.Gaab@scanlab.de> writes:
> I tried to order a text-column only by parts of the entries. Therefore I used regexp_matches(), but unfortunately I am loosing rows.

> SELECT regexp_matches('abc','[0-9]+'),  regexp_matches('123','[0-9]+');

> Does not return "{null}, {123}" but no result at all.

Yes, because regexp_matches returns a rowset of zero or more results.
The fine manual suggests putting it in a sub-select if what you want
is a null or a single result:

  SELECT ... , (SELECT regexp_matches(...)) FROM ...

			regards, tom lane



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


end of thread, other threads:[~2011-02-22 16:39 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-02-22 11:25 replace_matches does not return {null} Andreas Gaab <A.Gaab@scanlab.de>
2011-02-22 16:39 ` Tom Lane <tgl@sss.pgh.pa.us>

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