Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fD27f-0005r1-Mg for pgsql-general@arkaria.postgresql.org; Mon, 30 Apr 2018 06:17:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fD27e-0006Ox-6E for pgsql-general@arkaria.postgresql.org; Mon, 30 Apr 2018 06:17:14 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fD24e-0007w1-4s for pgsql-general@lists.postgresql.org; Mon, 30 Apr 2018 06:14:08 +0000 Received: from mx1.mailbox.org ([80.241.60.212]) by magus.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fD24a-0002LZ-Jt for pgsql-general@postgresql.org; Mon, 30 Apr 2018 06:14:07 +0000 Received: from smtp1.mailbox.org (smtp1.mailbox.org [80.241.60.240]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.mailbox.org (Postfix) with ESMTPS id B57BC42B99; Mon, 30 Apr 2018 08:14:03 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp1.mailbox.org ([80.241.60.240]) by spamfilter03.heinlein-hosting.de (spamfilter03.heinlein-hosting.de [80.241.56.117]) (amavisd-new, port 10030) with ESMTP id WhCkVzAZ9fdt; Mon, 30 Apr 2018 08:14:02 +0200 (CEST) Message-ID: <1524810037.2382.10.camel@cybertec.at> Subject: Re: Parameter passing in trigger function write in C From: Laurenz Albe To: a <372660931@qq.com>, pgsql-general In-Reply-To: References: Organization: Cybertec Content-Type: text/plain; charset="UTF-8" Date: Fri, 27 Apr 2018 08:20:37 +0200 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk a wrote: > I was request to write a trigger that perform the following function: > > 1, The trigger will be set to exam all statement that will result change of datas > > 2, The trigger will exam three information other than the data updated or inserted: > user name, password and reasons of change > > 3, It will record down, in some format, the time and content of the change. > > Therefore, I would need some way of passing parameters into the trigger function. > Can anyone give me some instructions on how to do it or, if it is possible?? The only information you can pass to a trigger function are the old and new values of the table row being changed and the constants you can supply to the trigger function during CREATE TRIGGER. Everything else will have to be drawn from the current state of the database. One thing you can do is to define your own GUC (configuration parameter) and set that before you run the data modifying SQL statement. Then you can read that information in the trigger. Yours, Laurenz Albe -- Cybertec | https://www.cybertec-postgresql.com