Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W828M-0000Du-Ak for pgsql-sql@arkaria.postgresql.org; Tue, 28 Jan 2014 06:26:54 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1W828L-0004bj-Qb for pgsql-sql@arkaria.postgresql.org; Tue, 28 Jan 2014 06:26:53 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W828K-0004bc-O4 for pgsql-sql@postgresql.org; Tue, 28 Jan 2014 06:26:52 +0000 Received: from sam.nabble.com ([216.139.236.26]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W828D-0004Yy-RJ for pgsql-sql@postgresql.org; Tue, 28 Jan 2014 06:26:52 +0000 Received: from [192.168.236.26] (helo=sam.nabble.com) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1W828B-00034c-Hd for pgsql-sql@postgresql.org; Mon, 27 Jan 2014 22:26:43 -0800 Date: Mon, 27 Jan 2014 22:26:43 -0800 (PST) From: ssylla To: pgsql-sql@postgresql.org Message-ID: <1390890403536-5789155.post@n5.nabble.com> 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> Subject: Re: Trigger function - variable for schema name [SOLVED] MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -0.8 (/) 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 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. -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql