Re: NOT HAVING clause?

From: Andrew - Supernews <andrew+nonews(at)supernews(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: NOT HAVING clause?
Date: 2006-01-25 00:11:00
Message-ID: slrndtdggk.d6t.andrew+nonews@atlantis.supernews.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 2006-01-24, Will Glynn <wglynn(at)freedomhealthcare(dot)org> wrote:
> You might try:
>
> SELECT some_column
> FROM some_table
> GROUP BY some_column
> HAVING SUM(CASE WHEN sort_order=1 THEN 1 ELSE 0 END) = 0;

SELECT some_column
FROM some_table
GROUP BY some_column
HAVING every(sort_order <> 1);

every() is in 8.1 at least (can't recall when it was introduced); it's the
same as bool_and(), i.e. an aggregate that returns true only if all inputs
are true. Why isn't there a corresponding any(), I wonder? (bool_or does
exist)

It should be possible to define bool_and() or every() in the usual way as
a custom aggregate even on versions that don't have them builtin.

--
Andrew, Supernews
http://www.supernews.com - individual and corporate NNTP services

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Foster, Stephen 2006-01-25 00:45:58 Setting expire date on insert/modify
Previous Message gianni.zammarchi@tiscali.it 2006-01-24 23:19:06 pgxml