pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tiziano Slack <slack83@hotmail.it>
To: pgsql-sql@postgresql.org
Subject: TG_TABLE_NAME as identifier
Date: Tue, 5 Feb 2008 09:45:14 +0100
Message-ID: <BAY109-W28A8D4A3264086A0C38DA5CE2C0@phx.gbl> (raw)

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/=

view thread (6+ messages)  latest in thread

Message-ID: <BAY109-W28A8D4A3264086A0C38DA5CE2C0@phx.gbl>
Permalink:  ../BAY109-W28A8D4A3264086A0C38DA5CE2C0@phx.gbl/
Also on:    postgresql.org/message-id/BAY109-W28A8D4A3264086A0C38DA5CE2C0@phx.gbl

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: slack83@hotmail.it
  Subject: Re: TG_TABLE_NAME as identifier
  In-Reply-To: <BAY109-W28A8D4A3264086A0C38DA5CE2C0@phx.gbl>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox