Re: Looping through string constants - Mailing list pgsql-general

From Scott Bailey
Subject Re: Looping through string constants
Date
Msg-id 4A838C76.3040806@comcast.net
Whole thread Raw
In response to Looping through string constants  (David Kerr <dmk@mr-paradox.net>)
Responses Re: Looping through string constants
List pgsql-general
>> Using arrays makes it a little less verbose and easier to manage IMO.
>>
>> SELECT v FROM unnest(array['a','b','c','d']) v
>>
>
> Is that 8.4? or is unnest from contrib/ ?
>
> thanks!
>
> Dave

Unnest is included in 8.4, but it's pretty much essential for working
with arrays. Pre 8.4, you'd add the function like so

CREATE OR REPLACE FUNCTION unnest(anyarray)
   RETURNS SETOF anyelement AS
$BODY$
SELECT $1[i] FROM
     generate_series(array_lower($1,1),
                     array_upper($1,1)) i;
$BODY$
   LANGUAGE 'sql' IMMUTABLE STRICT

pgsql-general by date:

Previous
From: "V S P"
Date:
Subject: [Q] parsing out String array
Next
From: Scott Bailey
Date:
Subject: Re: [Q] parsing out String array