using regexp_matches and array manipulation

From: Bret Schuhmacher <bret(at)welcometolazyhill(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: using regexp_matches and array manipulation
Date: 2008-07-19 01:04:20
Message-ID: 48813D94.9060409@welcometolazyhill.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Can anyone give me an example of how to use regexp_matches and use the
captured values?

For instance, if I have a delimited string "a,b,c" and I want to put
each letter into a variable so I can subsequently use those variables in
an insert statement, how would I do that? I know regexp_matches returns
a text array, but how do I assign the value to an array and then access
those values?

leaselog=# select regexp_matches('a,b,c','(.*),(.*),(.*)');

~ regexp_matches
- ----------------
~ {a,b,c}
(1 row)

I've tried select into, but that just created a table and didn't put the
values into an array variable.
leaselog=# select regexp_matches('a,b,c','(.*),(.*),(.*)') into foo;

Thanks in advance!

Rgds,

Bret
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)

iD8DBQFIgT2T/PgQIGRJuUcRAvMGAJ9VRNfc5ZZsFtS2LG8VJgPNNnL1wwCfewlf
Jih6ReqSTj6Pp9Ya3B2uMn8=
=HbPn
-----END PGP SIGNATURE-----

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2008-07-19 01:29:53 Re: UPDATE runs slow in a transaction
Previous Message Francisco Reyes 2008-07-19 00:25:50 Re: Backup/Restore of single table in multi TB database