Re: MAX() of 0 records.
От | Paul McGarry |
---|---|
Тема | Re: MAX() of 0 records. |
Дата | |
Msg-id | 3965A4D7.C489FCD8@opentec.com.au обсуждение исходный текст |
Ответ на | Re: MAX() of 0 records. (benoit@cyberdeck.net) |
Список | 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@opentec.com.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
Вложения
В списке pgsql-sql по дате отправления: