Skip site navigation (1) Skip section navigation (2)

Re: count(1) return 0?

From: Bill Moran <wmoran(at)potentialtech(dot)com>
To: Zak McGregor <zak(at)mighty(dot)co(dot)za>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: count(1) return 0?
Date: 2004-03-01 01:02:40
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-general
Zak McGregor wrote:
> On Sun, 29 Feb 2004 19:55:15 -0500
> Bill Moran <wmoran(at)potentialtech(dot)com> wrote:
>>Not really sure I understand what you want, but try something like this:
>>select case when count(*) > 0 then ''t'' else ''f'' end from ...
> Unfortunately that does not work. When the resultset contains no records
> whatsoever, I get no rows at all - so on case...else sort of expression within
> the select itself will work.
> What I am looking for is a way to select "0" if no rows are returned, or the
> total number of rows returned from the query otherwise.

I suspect that I still don't understand what you're trying to do, but ...

select case when count(*) > 0 then 1 else 0 end from ...

Was what I should have suggested.

Bill Moran
Potential Technologies

In response to

pgsql-general by date

Next:From: Stephen HowardDate: 2004-03-01 01:04:19
Subject: referring to computed values from the select list in the where and order clauses
Previous:From: Zak McGregorDate: 2004-03-01 01:02:29
Subject: Re: count(1) return 0?

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group