Search in historical table

From: Lorusso Domenico <domenico(dot)l76(at)gmail(dot)com>
To: pgsql-it-generale(at)lists(dot)postgresql(dot)org
Subject: Search in historical table
Date: 2023-06-05 00:11:31
Message-ID: CAJMpnG7GpgrUrDU14wjTs4gue3EOA7jStDMPLJRZsxtUUQYcTw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-it-generale

Hello guys,
I've going to design a bitemporal table.

The implementation foresees 2 tables:
- current_table
- historical_table
I store 2 different time dimensions: user and db.
"User time dimension" could be set by sql instructions.
"Db time dimension" is alway managed and replaced by trigger function.

Each insert of update on current_table stores the previous record on
hisorical_table.

Delete isn't allowed because I need to store some closing information, so,
the user must perform update setting close=true and pass the other
mandatory information (User must update the corresponding view_current_data
instead of current_table).

Ok, for now, it seems to be a quiet standard approach.

Question 1:
Which is the right approach? use 2 timestamp range fileds (one for "user
time" and the other for "db time") or 4 timestamp fields (a couple for each
dimension)?

Question 2:
How to create an index that allows query to extract records contained (also
partially contained) in a period?
I mean: give me each record valid from user point of view between
2023-01-01 and 2023-03-15 AND valid from db point of view between
2023-02-01 and 2023-05-15

Thank's in advance

--
Domenico L.

per stupire mezz'ora basta un libro di storia,
io cercai di imparare la Treccani a memoria... [F.d.A.]

Responses

Browse pgsql-it-generale by date

  From Date Subject
Next Message Luca Ferrari 2023-06-05 06:29:44 Re: Search in historical table
Previous Message Lorusso Domenico 2023-06-04 23:06:45 Composite type: Primary Key and validation