Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 26EBF6332BB for ; Tue, 30 Jun 2009 03:47:44 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 94292-09 for ; Tue, 30 Jun 2009 03:47:43 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from qw-out-2122.google.com (qw-out-2122.google.com [74.125.92.27]) by mail.postgresql.org (Postfix) with ESMTP id 0CA3F6331C4 for ; Tue, 30 Jun 2009 03:47:42 -0300 (ADT) Received: by qw-out-2122.google.com with SMTP id 3so939337qwe.61 for ; Mon, 29 Jun 2009 23:47:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:content-type; bh=9lvLhS2y443fMgA3Vt3qowcmBJqM53hkFP9XXCKEiPY=; b=FTJrVJX8GBXVSe6arbKLSurg8UuhjwE108nQEfylMhEB1QIW6wF/YgFS0R19VskA6M +1cz52p3ks7wbOhM16KIcrtYkqHAH/6mLT1+TdPJhl6rvG38Tk6uWG6O4YqGH8iDbZwj qk7cjPlDp/wRl6moruyTnOmxch61sSiPn653w= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=PTcAXUuSQMSp/8VyfQ0zHpBw99mA1z31aDIZtLPoMAVdgnRAnufomuU1qLEj4gxMVS L+rFF1TokXTnG/+hrf7Y9ZkjrXzoLJj7DX9w6gaG1aclMG1ootaM/RIWO1202cNOIWgP NA1L1R0ol/M54e+cs/7kS3wnHmjm2b30d+gvw= MIME-Version: 1.0 Received: by 10.229.81.140 with SMTP id x12mr1774891qck.35.1246344462150; Mon, 29 Jun 2009 23:47:42 -0700 (PDT) Date: Mon, 29 Jun 2009 23:47:42 -0700 Message-ID: <11c0133d0906292347q4c65cfe2m7b658232d0b13a9f@mail.gmail.com> Subject: Recording how a table is used From: Daniel Gordon To: pgsql-sql@postgresql.org Content-Type: multipart/alternative; boundary=00163631059def398d046d8b2eb0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=HTML_MESSAGE=0.001 X-Spam-Level: X-Archive-Number: 200907/21 X-Sequence-Number: 32762 --00163631059def398d046d8b2eb0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit I'm trying to record the results of a select statement into a separate table. I need the information selected, the column it was stored in, the table it was stored in, and the query that selected it. Everything I've read so far says that triggers can't trigger from select statements, and they don't have a variable that stores the query it triggered from. I would be happy with partial solutions since my other option is a complicated perl script that has to parse the query statement to figure out where it is looking for the information Also, my next step is to do the same for as many types of statements as possible, so if anyone knows how to retrieve the insert, update, or delete statement sent to the database from inside the trigger, that would be useful as well. Here is the table I'm trying to fill, in case it is useful create table sql_query_data_log ( id serial, create_ time timestamp DEFAULT now(), query varchar, table text, column text, data varchar ); --00163631059def398d046d8b2eb0 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable I'm trying to record the results of a select statement into a separate = table.=A0 I need the information selected, the column it was stored in, the= table it was stored in, and the query that selected it.=A0 Everything I= 9;ve read so far says that triggers can't trigger from select statement= s, and they don't have a variable that stores the query it triggered fr= om.=A0 I would be happy with partial solutions since my other option is a c= omplicated perl script that has to parse the query statement to figure out = where it is looking for the information

Also, my next step is to do the same for as many types of statements as= possible, so if anyone knows how to retrieve the insert, update, or delete= statement sent to the database from inside the trigger, that would be usef= ul as well.

Here is the table I'm trying to fill, in case it is useful
=
create table sql_query_data_log (
id serial,
create_ time timestamp= DEFAULT now(),
query varchar,
table text,
column text,
data varchar
);

--00163631059def398d046d8b2eb0--