From: | Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> |
---|---|
To: | Sgarbossa Domenico <domenico(dot)sgarbossa(at)eniac(dot)it> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: How to send multiple parameters to a pl/pgsql function |
Date: | 2009-10-21 09:23:05 |
Message-ID: | 162867790910210223u324cafaw224ce65894e576ca@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
>
> I know that postgresql array implementation is not right complete and that if just
> one element of array is NULL the basics array function (array_dims, array_upper, etc.) returns NULL.
> I need to send a list of parameters (which could contain NULL values) and evaluate the parameters excluding NULL values
> is this possible?
> any suggestion?
It's not true. Dimensions are stored independent to content.
postgres=# create or replace function foo(int[])
returns int as $$
declare s int = 0; i integer;
begin
for i in select generate_subscripts($1,1)
loop
s := s + coalesce($1[i],0);
end loop;
return s;
end;
$$ language plpgsql;
CREATE FUNCTION
postgres=# select foo(array[1,2]);
foo
─────
3
(1 row)
postgres=# select foo(array[1,2, null, 3]);
foo
─────
6
(1 row)
From | Date | Subject | |
---|---|---|---|
Next Message | Sergey Konoplev | 2009-10-21 12:48:12 | Index Scan/Bitmap Index Scan for queries with FTS and ORDER+LIMIT |
Previous Message | Thom Brown | 2009-10-21 09:17:59 | Re: PostgreSQL driver for Joomla review |