X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 6561A53236 for ; Mon, 2 May 2005 16:10:57 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 80728-09 for ; Mon, 2 May 2005 19:10:54 +0000 (GMT) Received: from iracema.dnscenter.com.br (iracema.dnscenter.com.br [67.15.81.98]) by svr1.postgresql.org (Postfix) with ESMTP id 70922536E9 for ; Mon, 2 May 2005 16:10:53 -0300 (ADT) Received: from cpanel by iracema.dnscenter.com.br with local (Exim 4.50) id 1DSgJb-0000IG-BU for pgsql-sql@postgresql.org; Mon, 02 May 2005 16:10:47 -0300 Received: from 201.0.112.250 ([201.0.112.250]) by www.presserv.org (Horde) with HTTP for ; Mon, 02 May 2005 16:10:46 -0300 Message-ID: <20050502161046.fu5wv62yyesgcwoc@www.presserv.org> Date: Mon, 02 May 2005 16:10:46 -0300 From: lucas@presserv.org To: pgsql-sql@postgresql.org Subject: Record Log Trigger MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 7bit User-Agent: Internet Messaging Program (IMP) H3 (4.0) X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - iracema.dnscenter.com.br X-AntiAbuse: Original Domain - postgresql.org X-AntiAbuse: Originator/Caller UID/GID - [32001 502] / [47 12] X-AntiAbuse: Sender Address Domain - presserv.org X-Source: X-Source-Args: X-Source-Dir: X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.385 tagged_above=0 required=5 tests=NO_REAL_NAME, UPPERCASE_25_50 X-Spam-Level: X-Archive-Number: 200505/22 X-Sequence-Number: 21335 Hi all, I am building a database in postgresql and I made a function that returns the system time and the current user... like this: CREATE OR REPLACE FUNCTION generate_idx() returns text as $$ select to_char(now(),'YYYYMMDDHHMISSUSTZ')||CURRENT_USER; $$ language 'SQL'; CREATE OR REPLACE FUNCTION TG_idxm() RETURNS trigger AS $$ BEGIN NEW.idxm = generate_idx(); RETURN NEW; END; $$ LANGUAGE plpgsql; And my all tables have the "idxm" field, its something like a log for the record, to know Who and When the record have changed. I.e: CREATE TABLE products( id serial primary key, description varchar(50), ... idxm varchar(100) ); CREATE TRIGGER TG_products_idxm BEFORE INSERT or UPDATE on products FOR EACH ROW EXECUTE PROCEDURE TG_idxm(); Okay, it runs fine... but my question is: Is it right??? In the future (when the database will be bigger with many of millions records) this functions for each table will depreceate my database performance??? Is there any other way to build it??? Thank you