Re: Trigger function - variable for schema name [SOLVED] - Mailing list pgsql-sql

From ssylla
Subject Re: Trigger function - variable for schema name [SOLVED]
Date
Msg-id 1390890403536-5789155.post@n5.nabble.com
Whole thread Raw
In response to Re: Trigger function - variable for schema name  (Glyn Astill <glynastill@yahoo.co.uk>)
Responses Re: Trigger function - variable for schema name [SOLVED]
List 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.



pgsql-sql by date:

Previous
From: Achilleas Mantzios
Date:
Subject: Re: Update ordered
Next
From: Herouth Maoz
Date:
Subject: Re: How to insert rows distributed evenly between referenced rows?