|
From: Gregory W. <gw...@co...> - 2004-05-09 22:42:44
|
Hi,
I have a question about how to query an empty table. (I have to query
the
table to find the maximum value of a field; if there are any entries at
all the
field is non-null.)
I used
last = do
events <- table event
restrict (events!sid .==. constant 1)
u <- project (cid << _max(events!cid))
return u
The fields are sid and cid, and the goal is to find the largest value
of cid. Since cid is non-null as a type, this gives an error if the
table
is empty.
If there are any entries at all in the table, there are over 100,000,
so I don't want to return the whole table just to see if it is
non-empty.
My question: is there a way to simply have the query return empty
list if the table is empty, in a way that typechecks, or
is it just as efficient to do a lazy query (no "project"), see if the
head
is non-empty and then repeat the query with the projection? Or is
there some better way of structuring this that I haven't learned yet?
By the way, the previous advice about using _default for auto-increment
fields works perfectly with PostgreSQL v. 7.4.2. Thanks for the hint.
I'm
slowly getting better at finding examples in the test programs but
I'm still very much an HDB newbie.
Best Wishes,
Greg
Gregory Wright
Antiope Assoicates LLC
gw...@an...
|