On Thu, Aug 13, 2009 at 08:30:07AM -0700, Scott Bailey wrote:
> >On Wed, Aug 12, 2009 at 08:45:58PM -0700, Scott Bailey wrote:
> >>CREATE OR REPLACE FUNCTION unnest(anyarray)
> >> RETURNS SETOF anyelement AS
> >>$BODY$
> >>SELECT $1[i] FROM
> >>generate_series(array_lower($1,1),
> >>
On Wed, Aug 12, 2009 at 08:45:58PM -0700, Scott Bailey wrote:
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
I'd recommen
On Wed, Aug 12, 2009 at 08:45:58PM -0700, Scott Bailey wrote:
> 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
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
On Wed, Aug 12, 2009 at 07:10:16PM -0400, Tom Lane wrote:
- David Kerr writes:
- > I'd like to loop through a group of constant string values using plpgsql
- > The best analog i can think of would be in a shell script
- > #!/usr/bin/ksh
-
- > for a in a b c d e; do
-
- Use VALUES?
looks like th
David Kerr wrote:
> I'd like to loop through a group of constant string values using plpgsql
> The best analog i can think of would be in a shell script
> #!/usr/bin/ksh
> for a in a b c d e; do
> echo $a
> done
> ./a.ksh
> a
> b
> c
> d
> e
> Is there some tricky way I can make that happen i
David Kerr writes:
> I'd like to loop through a group of constant string values using plpgsql
> The best analog i can think of would be in a shell script
> #!/usr/bin/ksh
> for a in a b c d e; do
Use VALUES?
regression=# create function foo() returns int as $$
regression$# declare s int := 0;
r