What can I use as a [non-aggregate] minimum function - Mailing list pgsql-general

From Paul Wehr
Subject What can I use as a [non-aggregate] minimum function
Date
Msg-id 60254.167.242.48.50.1008052213.squirrel@192.168.0.254
Whole thread Raw
In response to Re: how to create a database  (Stephan Szabo <sszabo@megazone23.bigpanda.com>)
Responses Re: What can I use as a [non-aggregate] minimum function
List 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



pgsql-general by date:

Previous
From: "Paul Wehr"
Date:
Subject: Re: Need SQL help, I'm stuck.
Next
From: Stephan Szabo
Date:
Subject: Re: Need SQL help, I'm stuck.