pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #7520: regexp_matches does not work as expected
2+ messages / 2 participants
[nested] [flat]

* BUG #7520: regexp_matches does not work as expected
@ 2012-09-05 01:31  sbasurto@soft-gator.com
  0 siblings, 1 reply; 2+ messages in thread

From: sbasurto@soft-gator.com @ 2012-09-05 01:31 UTC (permalink / raw)
  To: pgsql-bugs

The following bug has been logged on the website:

Bug reference:      7520
Logged by:          Sergio Basurto
Email address:      sbasurto@soft-gator.com
PostgreSQL version: 9.1.4
Operating system:   Gentoo
Description:        

I am using regexp_matches in a function like this
create or replace function test (v_string       in text)
returns varchar as $$
declare
i_strings               text[];
i_string                text[];

i_strings :=
regexp_matches(v_string,E'[a-zA-Z0-9:\\s\\-\\.#%]*:[A-Za-z0-9\\s\\-\\.#%]+','g');

The I use the results 
foreach i_string slice 1 in array i_strings
loop
    raise notice 'row = %',i_string;
end loop;

when I run the function like this
select test('1:Warehouse1;2:Warehouse2;');

postgresql complains:
ERROR:  query "SELECT
regexp_matches(v_string,E'[a-zA-Z0-9:\\s\\-\\.#%]*:[A-Za-z0-9\\s\\-\\.#%]+','g')"
returned more than one row

Off course I am expecting more than one row!

If I run:
select
regexp_matches('1:Warehouse1;2:Warehouse2;',E'[a-zA-Z0-9:\\s\\-\\.#%]*:[A-Za-z0-9\\s\\-\\.#%]+','g');
 regexp_matches 
----------------
 {1:Warehouse1}
 {2:Warehouse2}
(2 rows)






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

* Re: BUG #7520: regexp_matches does not work as expected
@ 2012-09-05 04:35  Tom Lane <tgl@sss.pgh.pa.us>
  parent: sbasurto@soft-gator.com
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2012-09-05 04:35 UTC (permalink / raw)
  To: sbasurto@soft-gator.com; +Cc: pgsql-bugs

sbasurto@soft-gator.com writes:
> I am using regexp_matches in a function like this
> create or replace function test (v_string       in text)
> returns varchar as $$
> declare
> i_strings               text[];
> i_string                text[];

> i_strings :=
> regexp_matches(v_string,E'[a-zA-Z0-9:\\s\\-\\.#%]*:[A-Za-z0-9\\s\\-\\.#%]+','g');

> postgresql complains:
> ERROR:  query "SELECT
> regexp_matches(v_string,E'[a-zA-Z0-9:\\s\\-\\.#%]*:[A-Za-z0-9\\s\\-\\.#%]+','g')"
> returned more than one row

As per David Johnston's response on pgsql-general, this isn't a bug:
simple assignments in plpgsql expect a simple source value, not a rowset.

Personally I'd just iterate over the regexp_matches result directly and
not bother trying to store it into a variable, for example

	for string_var in select regexp_matches(...) loop ...

			regards, tom lane




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


end of thread, other threads:[~2012-09-05 04:35 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2012-09-05 01:31 BUG #7520: regexp_matches does not work as expected sbasurto@soft-gator.com
2012-09-05 04:35 ` 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