agora inbox for pgsql-sql@postgresql.org
help / color / mirror / Atom feedFrom: ssylla <stefansylla@gmx.de>
To: pgsql-sql@postgresql.org
Subject: Re: Trigger function - variable for schema name [SOLVED]
Date: Mon, 27 Jan 2014 22:26:43 -0800 (PST)
Message-ID: <1390890403536-5789155.post@n5.nabble.com> (raw)
In-Reply-To: <1390820451.59644.YahooMailNeo@web133202.mail.ir2.yahoo.com>
References: <1390811996770-5788931.post@n5.nabble.com>
<1390819626.71225.YahooMailNeo@web133206.mail.ir2.yahoo.com>
<1390820451.59644.YahooMailNeo@web133202.mail.ir2.yahoo.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-sql>
That is exactly what I was looking for! It resolved all my problems and now I
can use the schema name as a variable in my trigger function, using
'execute' and the string concatenation parameters ('||') which I was not
able to implement before (thanks for the example Glyn!).
I finally used TG_TABLE_SCHEMA instead of passing the argument with TG_ARGV.
Here the complete solution:
CREATE OR REPLACE FUNCTION trigger_function1()
RETURNS trigger AS
$$
begin
EXECUTE 'select table2.id from ' || quote_ident(TG_TABLE_SCHEMA) ||
'.table2'
|| ' where value1 ' || ' = ' || quote_literal(new.value1) into
new.id;
new.columnx=function1(TG_TABLE_SCHEMA,value1);
return new;
end:
$$
language plpgsql;
CREATE TRIGGER trigger_function1
BEFORE INSERT
ON schema1.table1
FOR EACH ROW
EXECUTE PROCEDURE trigger_function1();
--
View this message in context: http://postgresql.1045698.n5.nabble.com/Trigger-function-variable-for-schema-name-tp5788931p5789155....
Sent from the PostgreSQL - sql mailing list archive at Nabble.com.
--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql
view thread (5+ messages) latest in thread
Message-ID: <1390890403536-5789155.post@n5.nabble.com>
Permalink: ../1390890403536-5789155.post@n5.nabble.com/
Also on: postgresql.org/message-id/1390890403536-5789155.post@n5.nabble.com
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: stefansylla@gmx.de
Subject: Re: Trigger function - variable for schema name [SOLVED]
In-Reply-To: <1390890403536-5789155.post@n5.nabble.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox