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

Поиск
Список
Период
Сортировка
От Paul Wehr
Тема What can I use as a [non-aggregate] minimum function
Дата
Msg-id 60254.167.242.48.50.1008052213.squirrel@192.168.0.254
обсуждение исходный текст
Ответ на Re: how to create a database  (Stephan Szabo <sszabo@megazone23.bigpanda.com>)
Ответы Re: What can I use as a [non-aggregate] minimum function  (Tom Lane <tgl@sss.pgh.pa.us>)
Список 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 по дате отправления:

Предыдущее
От: "Paul Wehr"
Дата:
Сообщение: Re: Need SQL help, I'm stuck.
Следующее
От: Stephan Szabo
Дата:
Сообщение: Re: Need SQL help, I'm stuck.