Trigger to change different row in same table - Mailing list pgsql-sql

From PostgreSQL Admin
Subject Trigger to change different row in same table
Date
Msg-id 46DD7634.4090408@productivitymedia.com
Whole thread Raw
In response to Re: Partial index on boolean - Sometimes fails to index scan  (Bryce Nesbitt <bryce1@obviously.com>)
List 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


pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: Cast on character columns in views
Next
From: PostgreSQL Admin
Date:
Subject: Re: Trigger to change different row in same table