MAX() of 0 records.

From: Paul McGarry <paulm(at)opentec(dot)com(dot)au>
To: pgsql-sql(at)postgresql(dot)org
Subject: MAX() of 0 records.
Date: 2000-07-07 01:44:15
Message-ID: 396535EF.8132CF80@opentec.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers pgsql-sql

Hello,

I wish to perform the following query in a plsql function upon an
update/insert/delete trigger:

UPDATE entry_stats
SET entry_maxprice=MAX(item_price)
FROM item
WHERE item.item_entry_id=NEW.item_entry_id
AND item.item_live = 't';

However there will be situations where there are no records for
a given item_entry_id with item_live='t'. Currently when I try
do update/insert a record so that this occurs I get the following
error 'ERROR: ExecutePlan: (junk) 'ctid' is NULL!' and the
insert/update attempt is rolled back.

In this scenario I want entry_stats.entry_maxprice to be set to zero
(which is also the default value for that column if it's any help).

Is there a good way of going about this or should I just be wrapping
the whole thing up in an
====
IF (COUNT(*) FROM item
WHERE item.item_entry_id=NEW.item_entry_id
AND item.item_live = 't')>0
THEN
UPDATE ... =MAX() ...
ELSE
UPDATE SET ... =0 ...
END IF
====
?

Thanks

--
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

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2000-07-07 03:29:42 Re: MAX() of 0 records.
Previous Message Bruce Momjian 2000-07-07 01:23:28 Re: [PATCHES] Patch for Linux-IA64

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2000-07-07 01:53:46 Re: Fix for pg_dump
Previous Message Chris Bitmead 2000-07-07 01:22:03 Re: PostgreSQL & the BSD License

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2000-07-07 03:29:42 Re: MAX() of 0 records.
Previous Message Brett W. McCoy 2000-07-07 01:12:43 Re: confused by select.