Search Postgresql Archives

Re: number of not null arguments

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>:
> 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

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux