From: | Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> |
---|---|
To: | kabilovmf(at)gmail(dot)com |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: number of not null arguments |
Date: | 2010-11-26 20:29:16 |
Message-ID: | AANLkTimwQA=5tRgrsMywKZHbbqi25Udq_K3vk7zuKEg9@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hello
this function doesn't exists, but you can you to write (min PostgreSQL 8.4)
create or replace function notnull_count(variadic anyarray) returns
int as $$select count(x)::int from unnest($1) g(x)$$ language sql;
it working just for scalar types:
pavel=# SELECT notnull_count(1, 1, NULL, NULL); notnull_count
───────────────
2
(1 row)
it doesn't working for arrays, but you can to little bit modify query
pavel=# SELECT notnull_count(array_upper(ARRAY[1,2,3],1),
array_upper(ARRAY[10,20,30],1), NULL, array_upper(ARRAY[NULL],1));
notnull_count
───────────────
3
(1 row)
next (but general solution) is custom function in C - it can be very simple
Regards
Pavel Stehule
2010/11/26 Murat Kabilov <kabilovmf(at)gmail(dot)com>:
> Hello,
> Is there a function which returns number of not null arguments?
> SELECT notnull_count(1, 1, NULL, NULL)
> notnull_count
> ---------------
> 2
> SELECT notnull_count(ARRAY[1,2,3], ARRAY[10,20,30], NULL, ARRAY[NULL])
> notnull_count
> ---------------
> 3
> Thanks
> --
> Murat Kabilov
From | Date | Subject | |
---|---|---|---|
Next Message | Marc Mamin | 2010-11-26 20:47:11 | Re: Help on explain analyze |
Previous Message | Martin Gainty | 2010-11-26 18:23:10 | Re: plpyhton |