Re: Record Log Trigger - Mailing list pgsql-sql

From CHRIS HOOVER
Subject Re: Record Log Trigger
Date
Msg-id NY696b37-43336dd8@companiongroup.com
Whole thread Raw
In response to Record Log Trigger  (lucas@presserv.org)
Responses Re: Record Log Trigger  (lucas@presserv.org)
List pgsql-sql
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;$$
LANGUAGEplpgsql;
 

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


pgsql-sql by date:

Previous
From: lucas@presserv.org
Date:
Subject: Record Log Trigger
Next
From: lucas@presserv.org
Date:
Subject: Function or Field?