From: PostgreSQL Admin <postgres@productivitymedia.com>
To: pgsql-sql@postgresql.org
Subject: Trigger to change different row in same table
Date: Tue, 04 Sep 2007 11:13:56 -0400
Message-ID: <46DD7634.4090408@productivitymedia.com> (raw)
In-Reply-To: <46DD6E44.4000505@obviously.com>
References: <46DCE263.6040207@obviously.com>
<46DD0E81.2000901@obviously.com>
<46DD6E44.4000505@obviously.com>
I want to write a trigger that updates a different row on the same
table. It's pretty basic: before the any row in his table updated I
want to set a only row that has the value true to false. I keep getting
this error:
SQL statement "update theirry.articles set master_featured = false where
master_featured = true"
PL/pgSQL function "master_featured_maintenance" line 4 at SQL statement
My basic trigger:
CREATE OR REPLACE FUNCTION theirry.master_featured_maintenance()
RETURNS TRIGGER AS
$master_featured_maintenance$
DECLARE
master_feature boolean;
BEGIN
update theirry.articles
set master_featured = false
where master_featured = true;
END;
$master_featured_maintenance$
LANGUAGE plpgsql;
CREATE TRIGGER master_featured_maintenance
BEFORE INSERT OR UPDATE ON theirry.articles
FOR EACH ROW EXECUTE PROCEDURE theirry.master_featured_maintenance();
Thanks in advance,
J
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 using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: postgres@productivitymedia.com
Subject: Re: Trigger to change different row in same table
In-Reply-To: <46DD7634.4090408@productivitymedia.com>
* 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