Re: [GENERAL] Variable as a variable name in PL/pgSQL

From: tolik(at)icomm(dot)ru (Anatoly K(dot) Lasareff)
To: Daniele Orlandi <daniele(at)orlandi(dot)com>
Cc: pgsql-general(at)postgreSQL(dot)org
Subject: Re: [GENERAL] Variable as a variable name in PL/pgSQL
Date: 1999-02-02 06:42:24
Message-ID: 87r9s971db.fsf@tolikus.hq.aaanet.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

>>>>> "DO" == Daniele Orlandi <daniele(at)orlandi(dot)com> writes:

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

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

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

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

DO> The function should look like the following:

DO> CREATE FUNCTION users_trig_func() RETURNS opaque AS '
DO> BEGIN

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

DO> RETURN NEW;
DO> END;
DO> ' LANGUAGE 'plpgsql';

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

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

Excuse my english :(

I think this is impossible in 'plpgsql', because it is pre-compilrd
language.

But there is, in my mind, no
problem write script on any 'usual' language, such as perl. This
script can take data from your table, and send nesessary SQL queries
to server.

--
Anatoly K. Lasareff Email: tolik(at)icomm(dot)ru
Senior programmer

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Daniele Orlandi 1999-02-02 15:44:34 Re: [GENERAL] Variable as a variable name in PL/pgSQL
Previous Message Dustin Sallings 1999-02-02 03:34:00 big bad join problems revisited