Re: [GENERAL] Looping through string constants

2009-08-13 Thread Sam Mason
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), > >>

Re: [GENERAL] Looping through string constants

2009-08-13 Thread Scott Bailey
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

Re: [GENERAL] Looping through string constants

2009-08-13 Thread Sam Mason
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

Re: [GENERAL] Looping through string constants

2009-08-12 Thread Scott Bailey
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

Re: [GENERAL] Looping through string constants

2009-08-12 Thread David Kerr
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

Re: [GENERAL] Looping through string constants

2009-08-12 Thread Tim Landscheidt
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

Re: [GENERAL] Looping through string constants

2009-08-12 Thread Tom Lane
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