Plpgsql Triggers and Variable Tablenames

From: "Steffers" <stef(at)chronozon(dot)dyndns(dot)org>
To: pgsql-interfaces(at)postgresql(dot)org
Subject: Plpgsql Triggers and Variable Tablenames
Date: 2000-05-25 22:28:00
Message-ID: 20000525222800.E5E911F57C@chronozon.dyndns.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces


Hello everyone,
I hope that this is the correct forum in which to post the
question I have.

Currently I have code which tries to do the following:

CREATE FUNCTION upd_history_no_location()
RETURNS opaque
AS 'BEGIN
new.history_id=SELECT (max(history_id)+1) FROM client
where client.CLIENT_ID=new.CLIENT_ID;
END;'
LANGUAGE 'plpgsql';

I plan on tying this trigger onto the 'client' table on
an INSERT condition. I will be using the same 'basic' trigger on 70-80
tables
or so. To stop pointless re-iteration of code therefore I tried to create a
dynamic trigger as follows :

CREATE FUNCTION upd_history_no_location(text)
RETURNS opaque
AS 'BEGIN
new.history_id=SELECT (max(history_id)+1) FROM $1
where $1.CLIENT_ID=new.CLIENT_ID;
END;'
LANGUAGE 'plpgsql';

Needless to say, this didnt work. It seems to CREATE
okay, but when I try to trigger the action. urm. no. nice error message.
(and each table will have the field CLIENT_ID, and history_id, thats
not really an issue =)

I have been told that this will work in tcl (and infact that is
the way it is working at the minute), seeing as how everything is in
python though (the program that ties into the database), I would prefer
to stick to two languages (python/[plpg]sql) and tcl doesnt really sit
well with me as a language (jst a personal bias from a long ago school
lecture).

So, the question is, can I do this somehow under plpgsql
or can I raise this as a feature request to the maintener ? (assuming
he/she is here and reading the list).

many thanks,
Stefs.

(p.s because of the structure of the database, i cant use OID's or
sequence id's, as the 'uniqueness' of this counter is also tied into
a clients number and a clients workorder number. (dont ask ;))

Browse pgsql-interfaces by date

  From Date Subject
Next Message Kevin Lo 2000-05-26 01:21:40 [DONE] PostgreSQL-7.0 binary for WinNT
Previous Message Tom Lane 2000-05-25 20:18:56 Re: Database names ...