Received: from localhost (unknown [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id A08342E0032 for ; Tue, 20 Nov 2007 12:13:09 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 31038-06 for ; Tue, 20 Nov 2007 12:12:58 -0400 (AST) Received: from sargon.lncsa.com (sargon.lncsa.com [212.99.8.251]) by postgresql.org (Postfix) with ESMTP id 594872E0038 for ; Tue, 20 Nov 2007 12:13:04 -0400 (AST) Received: from localhost (localhost.localdomain [127.0.0.1]) by sargon.lncsa.com (Postfix) with ESMTP id 7E938303A014 for ; Tue, 20 Nov 2007 17:13:02 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at lncsa.com Received: from sargon.lncsa.com ([127.0.0.1]) by localhost (sargon.lncsa.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9ZhJLT9aEDKa for ; Tue, 20 Nov 2007 17:13:02 +0100 (CET) Received: from zenon.apartia.fr (zenon.apartia.fr [10.0.3.1]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "zenon.apartia.fr", Issuer "ca.apartia.fr" (verified OK)) by sargon.lncsa.com (Postfix) with ESMTP id 58E20300E367 for ; Tue, 20 Nov 2007 17:13:02 +0100 (CET) Received: from trajan.apartia.fr (trajan.apartia.fr [10.0.3.121]) by zenon.apartia.fr (Postfix) with ESMTP id DD88E59C5B42C for ; Tue, 20 Nov 2007 17:12:58 +0100 (CET) Received: by trajan.apartia.fr (Postfix, from userid 1000) id C274D256ED73; Tue, 20 Nov 2007 17:12:58 +0100 (CET) Date: Tue, 20 Nov 2007 17:12:58 +0100 From: Louis-David Mitterrand To: pgsql-sql@postgresql.org Subject: dynmic column names inside trigger? Message-ID: <20071120161258.GA27106@apartia.fr> Mail-Followup-To: pgsql-sql@postgresql.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.17 (2007-11-01) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200711/97 X-Sequence-Number: 29625 Hi, I've got this trigger to clean up text entered in web forms: CREATE or replace FUNCTION sanitize_text() RETURNS "trigger" AS $$ declare begin if old.story is not null and new.story != old.story then new.story = translate(new.story, E'\x92\x96', '''-'); new.story = regexp_replace(new.story, E'\x9c', 'oe', 'g'); new.story = regexp_replace(new.story, E'\x85', '...', 'g'); end if; return new; end; $$ LANGUAGE plpgsql; CREATE TRIGGER sanitize_text_trig BEFORE INSERT or update ON story FOR EACH ROW EXECUTE PROCEDURE sanitize_text(); I'd like to use it on other tables an columns but how can the column name be dynamic inside the procedure. Passing the column name in the trigger declaration and using it as NEW.TG_ARGV[0] seems out of the question. Is there another solution out there? Thanks,