test aggregate functions without a dummy table

Started by Willy-Bas Loosalmost 18 years ago3 messagesgeneral
Jump to latest
#1Willy-Bas Loos
willybas@gmail.com

Hi,

I want to test the behavior of an an aggregate without creating a dummy
table for it.
But the code for it is horrible.
Is there no simpler way?

select max(foo)
from (select 1 as foo union select 2 as foo)bar;

thx

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Willy-Bas Loos (#1)
Re: test aggregate functions without a dummy table

"Willy-Bas Loos" <willybas@gmail.com> writes:

I want to test the behavior of an an aggregate without creating a dummy
table for it.
But the code for it is horrible.
Is there no simpler way?

select max(foo)
from (select 1 as foo union select 2 as foo)bar;

Perhaps VALUES?

regression=# select max(foo) from (values(1,2),(3,4),(5,6)) as v(foo,bar);
max
-----
5
(1 row)

regards, tom lane

#3Michael Fuhr
mike@fuhr.org
In reply to: Tom Lane (#2)
Re: test aggregate functions without a dummy table

On Fri, Jun 20, 2008 at 10:11:08AM -0400, Tom Lane wrote:

"Willy-Bas Loos" <willybas@gmail.com> writes:

I want to test the behavior of an an aggregate without creating a dummy
table for it.
But the code for it is horrible.
Is there no simpler way?

select max(foo)
from (select 1 as foo union select 2 as foo)bar;

Perhaps VALUES?

regression=# select max(foo) from (values(1,2),(3,4),(5,6)) as v(foo,bar);

Or perhaps using a set-returning function like generate_series():

test=> select max(foo) from generate_series(1, 100) as g(foo);
max
-----
100
(1 row)

--
Michael Fuhr