Re: Expressing a result set as an array (and vice versa)?

From: "Jim C(dot) Nasby" <jnasby(at)pervasive(dot)com>
To: PFC <lists(at)peufeu(dot)com>
Cc: Don Maier <dMaier(at)genome(dot)stanford(dot)edu>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Expressing a result set as an array (and vice versa)?
Date: 2006-03-27 13:48:31
Message-ID: 20060327134831.GJ80726@pervasive.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Sat, Mar 25, 2006 at 12:17:08AM +0100, PFC wrote:
>
>
> CREATE OR REPLACE FUNCTION foreach( liste INTEGER[] ) RETURNS SETOF
> INTEGER AS $$
> DECLARE
> i INTEGER;
> BEGIN
> FOR i IN 1..icount(liste) LOOP
> RETURN NEXT liste[i];
> END LOOP;
> END;
> $$ LANGUAGE plpgsql;

Seems like this should really exist in the backend...

> CREATE AGGREGATE array_accum (
> sfunc = array_append,
> basetype = anyelement,
> stype = anyarray,
> initcond = '{}'
> );
>
> SELECT array_accum( DISTINCT list_id ) FROM bookmarks;
> array_accum
> ---------------
> {1,2,3,4,5,7}

Couldn't you just use array()?
--
Jim C. Nasby, Sr. Engineering Consultant jnasby(at)pervasive(dot)com
Pervasive Software http://pervasive.com work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Jim C. Nasby 2006-03-27 13:49:43 Re: SQL Query Newbie Help
Previous Message Markus Schaber 2006-03-27 13:32:51 Re: functions in WHERE clause