pg.ddx.io pgsql-sql@postgresql.org mailing list archivehelp / color / mirror / Atom feed
Find NOT NULLs in a group of 20 columns 2+ messages / 2 participants [nested] [flat]
* Find NOT NULLs in a group of 20 columns @ 2011-01-11 02:14 gvim <gvimrc@gmail.com> 2011-01-11 02:45 ` Re: Find NOT NULLs in a group of 20 columns Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 1 reply; 2+ messages in thread From: gvim @ 2011-01-11 02:14 UTC (permalink / raw) To: pgsql-sql I'm struggling to find anything other than a complex stored proc to do this: Out of a group of 20 columns return the rows in which: 1. Only 1 of the 20 columns IS NOT NULL 2. More than 1 of the 20 columns IS NOT NULL Any ideas? gvim ^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Find NOT NULLs in a group of 20 columns 2011-01-11 02:14 Find NOT NULLs in a group of 20 columns gvim <gvimrc@gmail.com> @ 2011-01-11 02:45 ` Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 2+ messages in thread From: Tom Lane @ 2011-01-11 02:45 UTC (permalink / raw) To: gvim <gvimrc@gmail.com>; +Cc: pgsql-sql gvim <gvimrc@gmail.com> writes: > I'm struggling to find anything other than a complex stored proc to do this: > Out of a group of 20 columns return the rows in which: > 1. Only 1 of the 20 columns IS NOT NULL > 2. More than 1 of the 20 columns IS NOT NULL > Any ideas? Cast to int and add up? SELECT ... WHERE ((col1 is not null)::int + (col2 is not null)::int + ... (col20 is not null)::int) = 1 -- or > 1 regards, tom lane ^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2011-01-11 02:45 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2011-01-11 02:14 Find NOT NULLs in a group of 20 columns gvim <gvimrc@gmail.com> 2011-01-11 02:45 ` Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions for how to clone and mirror all data and code used for this inbox