Re: Expressing a result set as an array (and vice versa)? - Mailing list pgsql-sql

From Jim C. Nasby
Subject Re: Expressing a result set as an array (and vice versa)?
Date
Msg-id 20060327134831.GJ80726@pervasive.com
Whole thread Raw
In response to Re: Expressing a result set as an array (and vice versa)?  (PFC <lists@peufeu.com>)
Responses Re: Expressing a result set as an array (and vice versa)?
List 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@pervasive.com
Pervasive Software      http://pervasive.com    work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf       cell: 512-569-9461


pgsql-sql by date:

Previous
From: John DeSoi
Date:
Subject: Re: Problem using set-returning functions
Next
From: "Jim C. Nasby"
Date:
Subject: Re: SQL Query Newbie Help