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
-------------------------------------------------------------------------------