Re: Conditional on Select List

From: "Richard Broersma" <richard(dot)broersma(at)gmail(dot)com>
To: Fernando <fernando(at)ggtours(dot)ca>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Conditional on Select List
Date: 2008-05-13 16:10:17
Message-ID: 396486430805130910n4a15c6f1u6df69e47751b7f38@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, May 13, 2008 at 8:52 AM, Fernando <fernando(at)ggtours(dot)ca> wrote:
> SELECT IF(COUNT(colname) > 0, TRUE, FALSE) AS colname FROM table;

A rewrite of this query might do what you want:

SELECT colname_cnt > 0 AS Greaterthanzero
FROM ( SELECT COUNT( colname ) AS colname_cnt
FROM Table );

or

SELECT CASE COUNT( colname )
WHEN > 0
THEN TRUE
ELSE FALSE
END AS GreaterThanZero
FROM Table;
--
Regards,
Richard Broersma Jr.

Visit the Los Angles PostgreSQL Users Group (LAPUG)
http://pugs.postgresql.org/lapug

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Pau Marc Munoz Torres 2008-05-13 16:11:57 too many warnings
Previous Message Douglas McNaught 2008-05-13 16:09:30 Re: Conditional on Select List