X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id D3C50D1B1DC; Tue, 1 Jun 2004 19:04:36 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 18762-08; Tue, 1 Jun 2004 19:04:23 -0300 (ADT) Received: from gw.tssi.com (gw.tssi.com [198.147.197.1]) by svr1.postgresql.org (Postfix) with ESMTP id 011D9D1B18C; Tue, 1 Jun 2004 19:04:20 -0300 (ADT) Received: from gw.tssi.com (nolan@gw.tssi.com [127.0.0.1] (may be forged)) by gw.tssi.com (8.12.6/8.12.6) with ESMTP id i51M4KRF003457; Tue, 1 Jun 2004 17:04:20 -0500 Received: (from nolan@localhost) by gw.tssi.com (8.12.6/8.12.6/Submit) id i51M4K8Y003455; Tue, 1 Jun 2004 17:04:20 -0500 From: Mike Nolan Message-Id: <200406012204.i51M4K8Y003455@gw.tssi.com> Subject: Re: [PERFORM] Trigger & Function To: DLee@mail.maricopa.gov (Duane Lee - EGOVX) Date: Tue, 1 Jun 2004 17:04:19 -0500 (CDT) Cc: pgsql-general@postgresql.org ("PG General (E-mail)"), pgsql-performance@postgresql.org ("PSQL Performance (E-mail)") In-Reply-To: <64EDC403A1417B4299488BAE87CA7CBF01CD0E4B@maricopa_xcng0> from "Duane Lee - EGOVX" at Jun 01, 2004 02:03:40 PM X-Mailer: ELM [version 2.5 PL3] MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200406/65 X-Sequence-Number: 61448 > My problem is I defined the "before" and "after" > fields in the audit table as TEXT and when I try to move NEW or OLD into > these fields I get the error "NEW used in query that is not in a rule". You're trying to insert record data into a text field, that doesn't work. OLD and NEW can be used as either record identifiers (as in RETURN OLD) or column qualifiers (as in OLD.colname), but you can't intermingle them. I don't think postgres (pl/pgsql) has row-to-variable and variable-to-row functions like serialize and unserialize, that's probably what you'd need. It would probably be necessary to write something like that in C, since at this point pl/perl cannot be used for trigger functions. I've not tried using pl/php yet, the announcement for it says it can be used for trigger functions. My first thought is that even if there was a serialize/unserialize capabiity you might be able to write something using it that creates the log entry but not anything that allows you to query the log for specific column or row entries. It would probably require a MAJOR extension of SQL to add it to pg, as there would need to be qualifiers that can be mapped to specific tables and columns. Even if we had that, storing values coming from multiple tables into a single audit table would present huge challenges. I've found only two ways to implement audit logs: 1. Have separate log tables that match the structure of the tables they are logging. 2. Write a trigger function that converts columns to something you can store in a common log table. (I've not found a way to do this without inserting one row for each column being logged, though.) -- Mike Nolan