Re: How to Reference Current Table Name in plpgsql Trigger?

From: "steve boyle" <boylesa(at)dial(dot)pipex(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: How to Reference Current Table Name in plpgsql Trigger?
Date: 2002-01-08 17:11:07
Message-ID: a1fcop$1r53$1@news.tht.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Try looking @
http://www.il.postgresql.org/users-lounge/docs/7.0/user/c40874113.htm#AEN428
6

Specifically the special variable TG_RELNAME.

sb

"+I" <incognit(at)unifiedmind(dot)com> wrote in message
news:ebcd475a(dot)0112240514(dot)3f43431e(at)posting(dot)google(dot)com(dot)(dot)(dot)
> How do you, from within a function, reference the table name
> corresponding to the calling trigger?
>
> Specifically, I am creating an object map for all tables listed in
> km_object_types...
>
> create table km_object_types (
> table_name varchar(32) primary key,
> pretty_name varchar(100) not null,
> pretty_plural varchar(100)
> );
>
> create table object_map (
> table_name varchar(32) not null references km_object_types
> -- a single sequence is used for object_ids accross all tables
> object_id int not null unique
> primary key (table_name, object_id)
> );
>
> A trigger needs to insert object_id and table_name into object_map
> when inserts are made into any object table listed in km_object_types.
>
> The function to do this may look something like this, but I don't know
> how to reference the table name for the calling trigger...
>
> create function object_map_fn()
> returns opaque
> as '
> declare
> begin
>
> INSERT INTO km_object_map
> (object_id,table_name)
> VALUES
> (new.object_id,TABLE_NAME);
>
> return new;
> end;'
> language 'plpgsql';

Browse pgsql-general by date

  From Date Subject
Next Message Jason Earl 2002-01-08 17:17:03 Re: [GENERAL] Need help
Previous Message Frank Bax 2002-01-08 17:08:23 Re: what is in ../data/base ??