Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W7hji-0000b0-As for pgsql-sql@arkaria.postgresql.org; Mon, 27 Jan 2014 08:40:06 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1W7hjh-0003jo-Ez for pgsql-sql@arkaria.postgresql.org; Mon, 27 Jan 2014 08:40:05 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W7hjg-0003ji-OV for pgsql-sql@postgresql.org; Mon, 27 Jan 2014 08:40:04 +0000 Received: from sam.nabble.com ([216.139.236.26]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W7hja-0004MV-9k for pgsql-sql@postgresql.org; Mon, 27 Jan 2014 08:40:04 +0000 Received: from [192.168.236.26] (helo=sam.nabble.com) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1W7hjY-0000mr-Pl for pgsql-sql@postgresql.org; Mon, 27 Jan 2014 00:39:56 -0800 Date: Mon, 27 Jan 2014 00:39:56 -0800 (PST) From: ssylla To: pgsql-sql@postgresql.org Message-ID: <1390811996770-5788931.post@n5.nabble.com> Subject: Trigger function - variable for schema name MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: 1.1 (+) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org Dear list, I have the following trigger function an try to use TG_ARGV as a variable for the schema name of the table that caused the trigger: CREATE OR REPLACE FUNCTION trigger_function1() RETURNS trigger AS $BODY$ declare my_schema text; begin my_schema := TG_ARGV[0]; select table2.id into new.id from my_schema.table2; new.columnx=function1(my_schema,value1); return new; end: $$ language plpgsql CREATE TRIGGER trigger_function1 BEFORE INSERT ON schema1.table1 FOR EACH ROW EXECUTE PROCEDURE trigger_function1('schema1'); Using the trigger I get the following message: ERROR: schema "my_schema" does not exist So far I tried another option by temporarily changing the search path, but that might cause problems with other users who are working on other schemas of the database at the same time. That's why I would like to write the trigger in a way that it will only perform on the specified schema, but not changing the global search_path of the database. I also tried using dynamic sql with "execute format('...', TG_TABLE_SCHEMA); but that will only work inside the trigger, not if I want to pass the schema name to another function that is called from within the trigger. Stefan -- View this message in context: http://postgresql.1045698.n5.nabble.com/Trigger-function-variable-for-schema-name-tp5788931.html 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