TG_TABLE_NAME as identifier - Mailing list pgsql-sql

From Tiziano Slack
Subject TG_TABLE_NAME as identifier
Date
Msg-id BAY109-W28A8D4A3264086A0C38DA5CE2C0@phx.gbl
Whole thread Raw
Responses Re: TG_TABLE_NAME as identifier
Re: TG_TABLE_NAME as identifier
List pgsql-sql
Hello everybody! I'm newbie to plpgsql syntax. Can anyone tell where I'm getting wrong?

CREATE OR REPLACE FUNCTION tr_audit() RETURNS TRIGGER AS $tr_audit$
    BEGIN
        IF (TG_OP = 'UPDATE') THEN
        ...
        NEW.id = nextval(TG_TABLE_NAME || '_id_seq'::regclass);
        INSERT INTO TG_TABLE_NAME SELECT NEW.*;
        ELSIF (TG_OP = 'INSERT') THEN
        ...
        END IF;

        RETURN NULL;
    END;
$tr_audit$ LANGUAGE 'plpgsql';

returns

ERROR:  syntax error at or near "$1"
LINE 1: INSERT INTO  $1  SELECT  $2 .*
                     ^
QUERY:  INSERT INTO  $1  SELECT  $2 .*
CONTEXT:  SQL statement in PL/PgSQL function "tr_audit" near line 8

I tried some variants using INSERT INTO '|| TG_TABLE_NAME ||' SELECT NEW.* and quote_ident(TG_TABLE_NAME) with no luck! Unfortunately searches on the Net and old threads on this forum didn't help me.

Hope someone can do this!

Thanks in advance,

Tiziano.


Windows Live Spaces Push the Button! Crea il tuo blog e condividi le tue esperienze col mondo!

pgsql-sql by date:

Previous
From: "Ray Madigan"
Date:
Subject: Re: Except without elimination of non-distinct rows
Next
From: Richard Huxton
Date:
Subject: Re: TG_TABLE_NAME as identifier