Extract created and last modified data

From: Gordon McVey <grj(dot)mcvey(at)googlemail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Extract created and last modified data
Date: 2010-08-19 11:48:00
Message-ID: AANLkTi=W7vwAFxKEkFMHvm-hteNCBi1eJ5vYJA2qWDn0@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

I have a CMS with a table of items, and another table serving as a log
of operations performed on the items. The revelent table structure is
as follows:

items
itm_id | usr_id_create | itm_date_create | usr_id_modify |
itm_date_modify | .....

itm_id is a serial primary key.

usr_id_* are the keys of the users who created and last modified the
item.

item_date_* are timestamps for creation and last modification times.

changelog
itm_id | usr_id | log_timestamp | log_op

itm_id and usr_id are foreign keys into the respective item and user
tables. log_timestamp is when the last change was made and log_op was
the operation performed.

I realised that the creation and last modified data was being stored
in two places, and this is causing some issues with desynching. I'm
thinking of removing the creation and last modified fields from the
items table and using a view to fetch the create data and ID, and the
last modified date and ID from the changelog table instead. However
I'm not sure of how to do this, and how it would impact performance.

Can anybody help with writing the query to get a view that replicates
the items table except with the create and last modified user IDs and
timestamps loaded from the changelog table? If there is anybody who
has actually implemented something similar, what kind of performance
impact would it have?

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Oliveiros d'Azevedo Cristina 2010-08-19 13:24:48 Re: Extract created and last modified data
Previous Message Sergey Konoplev 2010-08-18 22:18:11 Re: plpgsql out parameter with select into