How to create audit fields on a table in Postgresql
I need to create a Postgresql table that contains 4 'audit' fields:
User ID Created
User Id Modified
Date Created
Date Modified
These fields should be populated through the use of defaults and / or triggers. For example, it is fine to use default values for all 4 fields when a record is created, but after creation, the "user id created" and "date created" fields should never change. On the other hand, I want the "user id modified" and "date modified" to change every time that the record gets updated.
I am looking for someone to help me complete the following "create table" statement:
create table test_table (id serial , name character varying , user_id_created , user_id_modified , datetime_created , datetime_modified )