Conditional on Select List

From: Fernando <fernando(at)ggtours(dot)ca>
To: pgsql-general(at)postgresql(dot)org
Subject: Conditional on Select List
Date: 2008-05-13 15:52:24
Message-ID: 4829B938.1060805@ggtours.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Is it possible to do this?

SELECT IF(COUNT(colname) > 0, TRUE, FALSE) AS colname FROM table;

What I want is to return a boolean, but when I tried SELECT
COUNT(colname)::BOOLEAN FROM table; it says it cannot cast bigint to
boolean.

Is there such IF function or do I have to create my own.

Thank you.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2008-05-13 15:54:37 Re: pg_standby / WAL archive-restore through system restarts
Previous Message Dimitri Fontaine 2008-05-13 15:47:06 Re: PG -v- MySQL