From: lucas@presserv.org
To: pgsql-sql@postgresql.org
Subject: Record Log Trigger
Date: Mon, 02 May 2005 16:10:46 -0300
Message-ID: <20050502161046.fu5wv62yyesgcwoc@www.presserv.org> (raw)
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: lucas@presserv.org
Subject: Re: Record Log Trigger
In-Reply-To: <20050502161046.fu5wv62yyesgcwoc@www.presserv.org>
References: <20050502161046.fu5wv62yyesgcwoc@www.presserv.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox