Re: [GENERAL] Conditional on Select List

2008-05-13 Thread Fernando
Thanks this is exactly what I need it. Fernando Tom Lane wrote: Fernando <[EMAIL PROTECTED]> writes: Is it possible to do this? SELECT IF(COUNT(colname) > 0, TRUE, FALSE) AS colname FROM table; SELECT COUNT(colname) > 0 AS colname FROM table; If you really like to type, you could us

Re: [GENERAL] Conditional on Select List

2008-05-13 Thread Richard Broersma
On Tue, May 13, 2008 at 8:52 AM, Fernando <[EMAIL PROTECTED]> 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

Re: [GENERAL] Conditional on Select List

2008-05-13 Thread Douglas McNaught
On Tue, May 13, 2008 at 11:52 AM, Fernando <[EMAIL PROTECTED]> wrote: > > Is it possible to do this? > > SELECT IF(COUNT(colname) > 0, TRUE, FALSE) AS colname FROM table; You should be able to use CASE for this. -Doug -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To ma

Re: [GENERAL] Conditional on Select List

2008-05-13 Thread Tom Lane
Fernando <[EMAIL PROTECTED]> writes: > Is it possible to do this? > SELECT IF(COUNT(colname) > 0, TRUE, FALSE) AS colname FROM table; SELECT COUNT(colname) > 0 AS colname FROM table; If you really like to type, you could use a CASE expression. regards, tom lane -- Sent

Re: [GENERAL] Conditional on Select List

2008-05-13 Thread Adam Rich
> > 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. > How about this? Logic al expresses are alrea

Re: [GENERAL] Conditional on Select List

2008-05-13 Thread Sam Mason
On Tue, May 13, 2008 at 11:52:24AM -0400, Fernando wrote: > 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 > b

Re: [GENERAL] Conditional on Select List

2008-05-13 Thread Joshua D. Drake
Fernando wrote: 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 cr

Re: [GENERAL] Conditional on Select List

2008-05-13 Thread Harald Armin Massa
Fernando, the "IF" function is called CASE WHEN condition THEN result [WHEN ...] [ELSE result] END read about it at http://www.postgresql.org/docs/8.3/static/functions-conditional.html best wishes, Harald On Tue, May 13, 2008 at 5:52 PM, Fernando <[EMAIL PROTECTED]> wrote: > >