[SQL] returning an array as a list of single-column rows... (different approach)

2007-12-23 Thread pgsql
An: pgsql-sql@postgresql.org Betreff: Re: [SQL] returning an array as a list fo single-column rows? The following will return the elements of an array each in its Own row. Using both array_lower() and array_upper() the number of array Elements and their internal index may vary from record to reco

Re: [SQL] returning an array as a list fo single-column rows?

2007-12-23 Thread Pavel Stehule
> > Yes I thought about it, but would rather have Pg do the array splitting. > For instance if the separator occurs in an array element there is no > built-in escaping: > > % select array_to_string(array['ee','dd','rr','f|f'],'|'); > array_to_string > - > ee|dd|rr|f|f if you ha

Re: [SQL] returning an array as a list fo single-column rows?

2007-12-23 Thread Louis-David Mitterrand
On Sun, Dec 23, 2007 at 10:27:09PM +0100, Pavel Stehule wrote: > On 23/12/2007, Louis-David Mitterrand > <[EMAIL PROTECTED]> wrote: > > Hi, > > > > is there a way to return a Pg array as a list of single-column row > > values? > > > > I am trying to circumvent DBI's lack of support for native datab

Re: [SQL] returning an array as a list fo single-column rows?

2007-12-23 Thread Pavel Stehule
On 23/12/2007, Louis-David Mitterrand <[EMAIL PROTECTED]> wrote: > Hi, > > is there a way to return a Pg array as a list of single-column row > values? > > I am trying to circumvent DBI's lack of support for native database > arrays and return the list of values from an ENUM as a perl array. > > Th

Re: [SQL] returning an array as a list fo single-column rows?

2007-12-23 Thread Louis-David Mitterrand
On Sun, Dec 23, 2007 at 10:19:26PM +0100, Pavel Stehule wrote: > Hello > > try > > create or replace function unpack(anyarray) > returns setof anyelement as $$ > select $1[i] > from generate_series(array_lower($1,1), array_upper($1,1)) g(i); > $$ language sql; > > postgres=# select * from

Re: [SQL] returning an array as a list fo single-column rows?

2007-12-23 Thread Pavel Stehule
Hello try create or replace function unpack(anyarray) returns setof anyelement as $$ select $1[i] from generate_series(array_lower($1,1), array_upper($1,1)) g(i); $$ language sql; postgres=# select * from unpack(array[1,2,3,4]); unpack 1 2 3 4 (4 rows) R

[SQL] returning an array as a list fo single-column rows?

2007-12-23 Thread Louis-David Mitterrand
Hi, is there a way to return a Pg array as a list of single-column row values? I am trying to circumvent DBI's lack of support for native database arrays and return the list of values from an ENUM as a perl array. Thanks, ---(end of broadcast)--

Re: [SQL] passing a multiple join to a function?

2007-12-23 Thread Louis-David Mitterrand
On Mon, Dec 17, 2007 at 12:27:34PM -0500, Rodrigo De León wrote: > On 12/17/07, Louis-David Mitterrand <[EMAIL PROTECTED]> wrote: > > I've got this ugly case statement that I'd like to hide in a function: > > Why don't you hide the entire query in a VIEW? That is probably the best solution. Thank