What can I use as a [non-aggregate] minimum function

From: Paul Wehr <postgresql(at)industrialsoftworks(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: What can I use as a [non-aggregate] minimum function
Date: 2001-12-11 06:30:13
Message-ID: 60254.167.242.48.50.1008052213.squirrel@192.168.0.254
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I need to find the minimum of dates in a number of tables, but "min(date)"
is, of course, an aggregate function. For example:

select key, min(a.date, b.date, c.date) as first_date
from table_a a, table_b b, table_c c
where a.key=b.key and a.key=c.key

right now I'm using:

case
when a.date < b.date and a.date < c.date then a.date
when b.date < c.date then b.date
else c.date
end

But there must be a better way. I've even looked into createing a
recursive function using an date[] as an argument (since I don't know how
to specify a function with a variable number of arguments)

Sorry if this is a FAQ but muc.lists.postgres doesn't return anything
useful, and the searchable archive seems to be down.

Thanks,

-paul

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Paul Wehr 2001-12-11 06:34:05 Re: Need SQL help, I'm stuck.
Previous Message Chris Albertson 2001-12-11 05:07:28 Re: What can I use as a [non-aggregate] minimum function