Re: Trigger function - variable for schema name [SOLVED]
| От | ssylla |
|---|---|
| Тема | Re: Trigger function - variable for schema name [SOLVED] |
| Дата | |
| Msg-id | 1390890403536-5789155.post@n5.nabble.com обсуждение исходный текст |
| Ответ на | Re: Trigger function - variable for schema name (Glyn Astill <glynastill@yahoo.co.uk>) |
| Ответы |
Re: Trigger function - variable for schema name [SOLVED]
|
| Список | 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 по дате отправления: