pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Paul McGarry <paulm@opentec.com.au>
To: pgsql-sql@postgresql.org
Subject: MAX() of 0 records.
Date: Fri, 07 Jul 2000 11:44:15 +1000
Message-ID: <396535EF.8132CF80@opentec.com.au> (raw)

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



view thread (18+ messages)  latest in thread

Message-ID: <396535EF.8132CF80@opentec.com.au>
Permalink:  ../396535EF.8132CF80@opentec.com.au/
Also on:    postgresql.org/message-id/396535EF.8132CF80@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
  Subject: Re: MAX() of 0 records.
  In-Reply-To: <396535EF.8132CF80@opentec.com.au>
  References: <396535EF.8132CF80@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