pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Paul McGarry <paulm@opentec.com.au>
To: benoit@cyberdeck.net
Cc: pgsql-sql@postgresql.org
Subject: Re: MAX() of 0 records.
Date: Fri, 07 Jul 2000 19:37:27 +1000
Message-ID: <3965A4D7.C489FCD8@opentec.com.au> (raw)
References: <200007070832.KAA23787@benoit.dagon.pdt>

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

Attachments:

  benoit.sql (application/x-unknown-content-type-sql_auto_file, 1.6K) download

view thread (18+ messages)  latest in thread

Message-ID: <3965A4D7.C489FCD8@opentec.com.au>
Permalink:  ../3965A4D7.C489FCD8@opentec.com.au/
Also on:    postgresql.org/message-id/3965A4D7.C489FCD8@opentec.com.au

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: paulm@opentec.com.au, benoit@cyberdeck.net
  Subject: Re: MAX() of 0 records.
  In-Reply-To: <3965A4D7.C489FCD8@opentec.com.au>
  References: <200007070832.KAA23787@benoit.dagon.pdt> <3965A4D7.C489FCD8@opentec.com.au>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox