Re: Trigger function - variable for schema name [SOLVED]

From: ssylla <stefansylla(at)gmx(dot)de>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Trigger function - variable for schema name [SOLVED]
Date: 2014-01-28 06:26:43
Message-ID: 1390890403536-5789155.post@n5.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-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.html
Sent from the PostgreSQL - sql mailing list archive at Nabble.com.

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Herouth Maoz 2014-01-28 11:30:14 Re: How to insert rows distributed evenly between referenced rows?
Previous Message Achilleas Mantzios 2014-01-27 15:49:10 Re: Update ordered