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 8869E53485 for ; Tue, 3 May 2005 09:14:58 -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 18651-06 for ; Tue, 3 May 2005 12:14: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 DD52253378 for ; Tue, 3 May 2005 09:14:53 -0300 (ADT) Received: from cpanel by iracema.dnscenter.com.br with local (Exim 4.50) id 1DSwIe-0002OE-7e; Tue, 03 May 2005 09:14:52 -0300 Received: from 200.158.187.88 ([200.158.187.88]) by www.presserv.org (Horde) with HTTP for ; Tue, 03 May 2005 09:14:52 -0300 Message-ID: <20050503091452.v0tk3a2hcnqc04g8@www.presserv.org> Date: Tue, 03 May 2005 09:14:52 -0300 From: lucas@presserv.org To: CHRIS HOOVER Cc: pgsql-sql@postgresql.org Subject: Re: Record Log Trigger References: In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format="flowed" 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=1.146 tagged_above=0 required=5 tests=AWL, NO_REAL_NAME, RCVD_IN_NJABL_PROXY X-Spam-Level: * X-Archive-Number: 200505/32 X-Sequence-Number: 21345 Well... Right, I will use to_timestamp() function instead of now() function. But, what is the performance for those Triggers??? Considering that all tables will have this Trigger and will check for each update or insert. Thanks Quoting CHRIS HOOVER : > One change you might want to look at is not using the now() function. > According to the docs, the now() function always returns the start of the > transaction time. So, if your code is using transaction blocks, the time may > not be what you are expecting. > > This is what I had do to in my trigger to get the current clock time: > to_char(to_timestamp(timeofday(),\'Dy Mon DD HH24:MI:SS.US YYYY\') > > > HTH, > > Chris > ------------------( Forwarded letter 1 follows )--------------------- > Date: Mon, 02 May 2005 16:10:46 -0300 > To: pgsql-sql@postgresql.org.comp > From: lucas@presserv.org.comp > Sender: pgsql-sql-owner+m21335@postgresql.org.comp > Subject: [SQL] Record Log Trigger > > 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 > > ---------------------------(end of broadcast)--------------------------- > TIP 5: Have you checked our extensive FAQ? > > http://www.postgresql.org/docs/faq >