TG_TABLE_NAME as identifier

From: Tiziano Slack <slack83(at)hotmail(dot)it>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: TG_TABLE_NAME as identifier
Date: 2008-02-05 08:45:14
Message-ID: BAY109-W28A8D4A3264086A0C38DA5CE2C0@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.
_________________________________________________________________
Organizza le tue feste e condividine le foto con Windows Live Eventi!
http://home.services.spaces.live.com/events/

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Richard Huxton 2008-02-05 09:32:50 Re: TG_TABLE_NAME as identifier
Previous Message Ray Madigan 2008-02-05 03:23:03 Re: Except without elimination of non-distinct rows