Trigger to change different row in same table

From: PostgreSQL Admin <postgres(at)productivitymedia(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Trigger to change different row in same table
Date: 2007-09-04 15:13:56
Message-ID: 46DD7634.4090408@productivitymedia.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message PostgreSQL Admin 2007-09-04 15:27:32 Re: Trigger to change different row in same table
Previous Message Tom Lane 2007-09-04 15:03:08 Re: Cast on character columns in views