Re: number of not null arguments
| От | Pavel Stehule |
|---|---|
| Тема | Re: number of not null arguments |
| Дата | |
| Msg-id | AANLkTimwQA=5tRgrsMywKZHbbqi25Udq_K3vk7zuKEg9@mail.gmail.com обсуждение исходный текст |
| Ответ на | number of not null arguments (Murat Kabilov <kabilovmf@gmail.com>) |
| Список | 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@gmail.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
В списке pgsql-general по дате отправления: