Variable as a variable name in PL/pgSQL

From: Daniele Orlandi <daniele(at)orlandi(dot)com>
To: pgsql-general(at)postgreSQL(dot)org
Subject: Variable as a variable name in PL/pgSQL
Date: 1999-02-01 18:42:42
Message-ID: 36B5F5A2.E6BAD3BA@orlandi.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


I'm trying to implement a sort of templates for a user database.

I tought of two possibilities. In the first I have a table like this:

CREATE TABLE templates
(
tplname varchar(32),
fieldname varchar(32),
value varchar(32)
);

Where I specify the value to be assigned to each field of the user's tuple.
I started writing a trigger to force the template values in the user's record
whenever it's updated or inserted. I'm using PL/pgSQL, and I'd like to continue
using it.

The function should look like the following:

CREATE FUNCTION users_trig_func() RETURNS opaque AS '
BEGIN

FOR row IN SELECT * FROM templates WHERE tplname = new.template;
NEW."row.fieldname" := row.fieldvalue;
END LOOP;

RETURN NEW;
END;
' LANGUAGE 'plpgsql';

Obviously the problem is the >>>NEW."row.fieldname" := expr<<< statememt.
I dont know how (if possible at all) to assign a variabile whose name is
contained in another variable, something like eval() in PHP3.

Is there a syntax or a hack ?
Whould it be hard to implement it at language level ?

Thanks in advance!

Regards.

--
Daniele

-------------------------------------------------------------------------------
We are using Linux daily to UP our productivity - so UP yours!
(Adapted from Pat Paulsen by Joe Sloan)
-------------------------------------------------------------------------------
Dal 28-09-1998, con un solo POP abbiamo fatto guadagnare a telecom italia
15.617.190 Lire solo in scatti alla risposta. Non male eh ?
-------------------------------------------------------------------------------
Daniele Orlandi - Utility Line Italia - http://www.orlandi.com
Via Mezzera 29/A - 20030 - Seveso (MI) - Italy
-------------------------------------------------------------------------------

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Dustin Sallings 1999-02-01 19:18:26 big bad join problems
Previous Message Marcio Macedo 1999-02-01 16:36:34 Re: [INTERFACES] web interface for v.6.4.2