X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id DCFA0DBB96 for ; Thu, 24 Nov 2005 01:23:14 -0400 (AST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 45373-07-3 for ; Thu, 24 Nov 2005 05:23:13 +0000 (GMT) X-Greylist: delayed 01:00:00.137504 by SQLgrey- Received: from anu.ie (mail.anu.net [213.247.49.236]) by svr1.postgresql.org (Postfix) with ESMTP id 35241DBBD5 for ; Thu, 24 Nov 2005 01:23:11 -0400 (AST) Received: from kenxp (68.40.184.254) by anu.ie with ESMTP (Eudora Internet Mail Server X 3.2.8b1) for ; Thu, 24 Nov 2005 04:23:07 +0000 From: "Ken Winter" To: "PostgreSQL pg-sql list" Subject: Date: Wed, 23 Nov 2005 23:23:05 -0500 Message-ID: <004e01c5f0ae$c4d4bfe0$6503a8c0@kenxp> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.6626 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 Importance: Normal X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.345 required=5 tests=[MISSING_SUBJECT=1.345] X-Spam-Score: 1.345 X-Spam-Level: * X-Archive-Number: 200511/229 X-Sequence-Number: 23480 In PL/pgSQL, is there a way to put a *variable* column-name in a dot notation reference to a RECORD column? For example, suppose I want to write a function like the following, = which is to be called by a "BEFORE INSERT" trigger: CREATE OR REPLACE FUNCTION foo ( ) RETURNS TRIGGER AS=20 ' DECLARE=20 var VARCHAR; BEGIN var :=3D TG_ARGV[0] =20 NEW. :=3D = ''whatever''; RETURN NEW; =20 END; ' LANGUAGE 'plpgsql' ; The aim of this uninteresting function is to assign the value 'whatever' = to the table column that is passed in by the calling trigger as TG_ARGV[0], i.e. the first calling argument. =20 What I don't know is what to put into the dot notation in place of = "." so that the column of NEW that = is addressed by the assignment statement is the one passed in as the first argument. Is there any PL/pgSQL construct that could be substituted in = here to achieve this result? If not, can anybody suggest a way to write a trigger-called function = that would accomplish the same result? In case it's not obvious, the underlying goal is to write a single trigger-called function that could modify different columns for each = trigger that called it, where each trigger specified the target column by a = calling argument (or by any other viable mechanism). ~ TIA ~ Ken