X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 9066E9FA64B for ; Fri, 23 Jun 2006 14:48:26 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 69450-02 for ; Fri, 23 Jun 2006 14:48:15 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 60A059FA60B for ; Fri, 23 Jun 2006 14:48:16 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id k5NHm89D017078; Fri, 23 Jun 2006 13:48:08 -0400 (EDT) To: Andrew Sullivan cc: pgsql-sql@postgresql.org Subject: Re: Fwd: Start up question about triggers In-reply-to: <20060623173504.GC12422@phlogiston.dyndns.org> References: <006901c696c1$d2af82d0$6400a8c0@Dell4500> <200606231548.k5NFmhSW028183@auth-smtp.hol.gr> <20060623173504.GC12422@phlogiston.dyndns.org> Comments: In-reply-to Andrew Sullivan message dated "Fri, 23 Jun 2006 13:35:04 -0400" Date: Fri, 23 Jun 2006 13:48:08 -0400 Message-ID: <17077.1151084888@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200606/262 X-Sequence-Number: 25498 Andrew Sullivan writes: > On Fri, Jun 23, 2006 at 06:48:49PM +0300, Forums @ Existanze wrote: >> Then there exist a TG_QUERY parameter that we could use to get the actual >> query ran by a user, so if I ran the imaginary query > Which "actual query"? By the time the trigger fires, the query might > already have been rewritten, I think. No? I _think_ that even > BEFORE triggers happen after the rewriter stage is called, but > someone who has more clue will be able to correct me if I'm wrong. Even if you could get hold of the user query text, it'd be a serious mistake to imagine that it tells you everything you need to know about the update. Aside from rule rewrites, previous BEFORE triggers could have changed fields that are mentioned nowhere in the query. The only safe way to determine what's going on is to compare the OLD and NEW row values. regards, tom lane