Re: array/function question

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
Cc: Joshua Berry <yoberi(at)gmail(dot)com>, postgresql Forums <pgsql-general(at)postgresql(dot)org>
Subject: Re: array/function question
Date: 2009-05-19 12:56:24
Message-ID: 162867790905190556o47563938i4b024a6a3d0aa5c1@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

2009/5/19 Alvaro Herrera <alvherre(at)commandprompt(dot)com>:
> Pavel Stehule escribió:
>
>> postgres=# create or replace function xx(anyarray, anyarray) returns
>> bool[] as $$
>> select array(select (select x = any(select y from unnest($2) g2(y)))
>> from unnest($1) g(x))
>> $$ language sql immutable;
>> CREATE FUNCTION
>
> There ain't no unnest() function in 8.3 ...

I am sorry

create or replace function unnest(anyarray) returns setof anyelement as $$
select $1[i] from generate_series(array_lower($1,1), array_upper($1,1)) g(i)
$$ language sql immutable;

when I looked on my code, it could be simplified

>> postgres=# create or replace function xx(anyarray, anyarray) returns
>> bool[] as $$
>> select array(select (select x = any($2)))
>> from unnest($1) g(x))
>> $$ language sql immutable;

regards
Pavel Stehule

>
> --
> Alvaro Herrera                                http://www.CommandPrompt.com/
> PostgreSQL Replication, Consulting, Custom Development, 24x7 support
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Stephane Bortzmeyer 2009-05-19 13:05:21 Restoring a database from original files (Was: Need help
Previous Message Alvaro Herrera 2009-05-19 12:52:28 Re: array/function question