Re: MAX() of 0 records.

From: Paul McGarry <paulm(at)opentec(dot)com(dot)au>
To: benoit(at)cyberdeck(dot)net
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: MAX() of 0 records.
Date: 2000-07-07 09:37:27
Message-ID: 3965A4D7.C489FCD8@opentec.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi Benoit,

> I once had the same problem with an int4 column and solved it by
> using the function below :
>
> CREATE FUNCTION "nulliszero" (int4 )
> RETURNS int4 AS
> 'SELECT 0 WHERE $1 IS NULL
> UNION SELECT $1 WHERE $1 IS NOT NULL' LANGUAGE 'SQL';
>
> Your request then would look like :
> (...)
> SET entry_maxprice=nulliszero(MAX(item_price));
> (...)

Thanks, I'm afraid that doesn't help in this context (see attached
sql). I'm sure it will come in handy some time though.

The problem isn't that MAX(item_price) returns null, it's that it
causes an error. From what I have distilled from the bugs/hackers
list where Tom has kindly written a lengthy response/discussion
of the problem it seems that in this situation (when no rows
match the where condition) the MAX (or min or count or any
aggregate function?) would cause an implicit grouping to
occur around a null field which the backend doesn't like.

I'd read Tom's post if you are interested though, it probably
makes more sense!

--
Paul McGarry mailto:paulm(at)opentec(dot)com(dot)au
Systems Integrator http://www.opentec.com.au
Opentec Pty Ltd http://www.iebusiness.com.au
6 Lyon Park Road Phone: (02) 9878 1744
North Ryde NSW 2113 Fax: (02) 9878 1755

Attachment Content-Type Size
benoit.sql application/x-unknown-content-type-sql_auto_file 1.6 KB

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Patrick Jacquot 2000-07-07 09:44:30 Re: confused by select.
Previous Message brianb-pgsql 2000-07-07 09:09:24 Search for underscore w/ LIKE