Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fFbzV-0000sW-D3 for pgsql-general@arkaria.postgresql.org; Mon, 07 May 2018 08:59:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fFbzU-0003iz-4F for pgsql-general@arkaria.postgresql.org; Mon, 07 May 2018 08:59:28 +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 1fFbzT-0003io-SE for pgsql-general@lists.postgresql.org; Mon, 07 May 2018 08:59:27 +0000 Received: from mx2.mailbox.org ([80.241.60.215]) by magus.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fFbzQ-00050a-M9 for pgsql-general@postgresql.org; Mon, 07 May 2018 08:59:27 +0000 Received: from smtp2.mailbox.org (smtp2.mailbox.org [80.241.60.241]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx2.mailbox.org (Postfix) with ESMTPS id B1AC440F2D; Mon, 7 May 2018 10:59:22 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by spamfilter03.heinlein-hosting.de (spamfilter03.heinlein-hosting.de [80.241.56.117]) (amavisd-new, port 10030) with ESMTP id X_9E5Ntceg_t; Mon, 7 May 2018 10:59:21 +0200 (CEST) Message-ID: <1525683560.2414.8.camel@cybertec.at> Subject: Re: Is it possible to get username information while writingtrigger? From: Laurenz Albe To: a <372660931@qq.com>, pgsql-general Date: Mon, 07 May 2018 10:59:20 +0200 In-Reply-To: References: <1525679840.2414.3.camel@cybertec.at> Organization: Cybertec Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk a wrote: > Please allow me to ask few more questions: > > 1, Since I'm writing a C trigger function, is there any method for me to get some of the > basic information like the follow: > > (1) Total number of rows; > (2) Rows' names; > (3) Value of OLD and NEW; > > 2, Is there any possibility of passing the SQL statement it self into the trigger? > > 3, Is it possible for me to exam before statement trigger so that I would be able to loop it > once and copying the update information to the rest of rows. I don't know if there is a reliable way to get the SQL statement from a C trigger. For the other things, perhaps a statement level trigger with transition relations can help. You can then access the transition relations from your C code with the tg_oldtable and tg_newtable tuplestores. (https://www.postgresql.org/docs/current/static/trigger-interface.html) Yours, Laurenz Albe -- +43-670-6056265 Cybertec Schönig & Schönig GmbH Gröhrmühlgasse 26, A-2700 Wiener Neustadt Web: https://www.cybertec-postgresql.com