Re: [Trigger] Help needed with NEW.* and TG_TABLE_NAME

From: Stuart <sfbarbee(at)earthlink(dot)net>
To: Torsten Zühlsdorff <foo(at)meisterderspiele(dot)de>, pgsql-sql(at)postgresql(dot)org
Subject: Re: [Trigger] Help needed with NEW.* and TG_TABLE_NAME
Date: 2010-05-11 22:06:58
Message-ID: 1273615618.1838.5.camel@Nokia-N900-02-8
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Torsten,

Usually, the “insert ... (select ...)” has the select portion enclosed in parenthesis. Don't know if solution is that simple but did not see it in your examples. It may be worth a try.

Stuart

----- Original message -----
> Hello,
>
> i have a problem with a trigger written in pl/pgsql.
>
> It looks like this:
>
> CREATE OR REPLACE FUNCTION versionize()
> RETURNS TRIGGER
> AS $$
> BEGIN
>
>      NEW.revision := addContentRevision (OLD.content_id, OLD.revision);
>
>      /* not working line, just a stub:
>      EXECUTE 'INSERT INTO ' || TG_TABLE_NAME  || ' SELECT $1 ' USING NEW;
>      */
>
>      RETURN NULL;
>
> END;
> $$ LANGUAGE 'plpgsql' VOLATILE;
>
> The function should be used at different tables and is invoked after
> UPDATEs. Everything what happens is the function call of
> addContentRevision. After this call all data (with the updated revision
> column) should be stored in the table as a new row.
>
> My problem: the aim-table is not static. It's just always the table
> which invoked the trigger. The trigger itself could be called at many
> tables. I've tried some other ways of expressing the INSERT but nothing
> worked:
> - 'INSERT INTO ' || TG_TABLE_NAME  || ' SELECT NEW.*'
> - INSERT INTO TG_TABLE_NAME SELECT NEW.*
> - EXECUTE 'INSERT INTO ' || TG_TABLE_NAME  USING NEW;
>
> Do you have any hints?
>
> Greetings from Germany,
> Torsten
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Louis-David Mitterrand 2010-05-12 05:41:44 best paging strategies for large datasets?
Previous Message Torsten Zühlsdorff 2010-05-11 14:26:29 Re: [Trigger] Help needed with NEW.* and TG_TABLE_NAME