making trigger on delete, set 'affected rows' correctly

From: Grzegorz Jaśkiewicz <gryzman(at)gmail(dot)com>
To: "Postgres General List" <pgsql-general(at)postgresql(dot)org>
Subject: making trigger on delete, set 'affected rows' correctly
Date: 2008-10-15 09:21:35
Message-ID: 2f4958ff0810150221n32991391n4f4fc7bb0a53dd6d@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hey list,

so I was wondering. Since many ppl depend on 'affected rows', we have here a
trigger running on delete. It will update the table, and set certain fields
to false on delete, return NULL - so it will look like:

CREATE OR REPLACE FUNCTION ondelete_update() returns trigger as
$_$
BEGIN
IF OLD.foo <> false THEN
EXECUTE 'UPDATE ' || TG_RELNAME || ' SET foo = 'true' WHERE rid = ' ||
OLD.rid ;
END IF;
RETURN NULL;
END;
$_$
LANGUAGE 'plpgsql';

Now, this on every delete will return 'affected rows count = 0'. C

--
GJ

Browse pgsql-general by date

  From Date Subject
Next Message Ivan Voras 2008-10-15 09:30:40 Re: Backup strategies
Previous Message Peter Vanderborght 2008-10-15 09:03:59 Querying on partitioned tables