Skip to Main Content
IBM Data and AI Ideas Portal for Customers


This portal is to open public enhancement requests against products and services offered by the IBM Data & AI organization. To view all of your ideas submitted to IBM, create and manage groups of Ideas, or create an idea explicitly set to be either visible by all (public) or visible only to you and IBM (private), use the IBM Unified Ideas Portal (https://ideas.ibm.com).


Shape the future of IBM!

We invite you to shape the future of IBM, including product roadmaps, by submitting ideas that matter to you the most. Here's how it works:


Search existing ideas

Start by searching and reviewing ideas and requests to enhance a product or service. Take a look at ideas others have posted, and add a comment, vote, or subscribe to updates on them if they matter to you. If you can't find what you are looking for,


Post your ideas

Post ideas and requests to enhance a product or service. Take a look at ideas others have posted and upvote them if they matter to you,

  1. Post an idea

  2. Upvote ideas that matter most to you

  3. Get feedback from the IBM team to refine your idea


Specific links you will want to bookmark for future use

Welcome to the IBM Ideas Portal (https://www.ibm.com/ideas) - Use this site to find out additional information and details about the IBM Ideas process and statuses.

IBM Unified Ideas Portal (https://ideas.ibm.com) - Use this site to view all of your ideas, create new ideas for any IBM product, or search for ideas across all of IBM.

ideasibm@us.ibm.com - Use this email to suggest enhancements to the Ideas process or request help from IBM for submitting your Ideas.

IBM Employees should enter Ideas at https://ideas.ibm.com


Status Not under consideration
Workspace Db2
Created by Guest
Created on Apr 24, 2018

Field-level changes using temporal tables

We're using DB2 temporal tables (in BigSQL) to track history on some of our core tables, and have the following need from downstream systems that use this data.
 
Is there a way to track column level changes using DB2 temporal tables to pull out which columns have changed, not just the fact that a change has occurred. We've considered table triggers, however, they seem cumbersome & code-heavy.
 
What we’re looking for is to compare two rows – one in current and another in history, and maintain a list of all fields that have different values between the two. Then, the consumers of the data from this table can get changes for the columns they’re interested in.
 
For example, consider a table MyTable with the following 6 columns
Col1 
Col2 
Col3 
Col4 
Col5 
Col6 
 
Say Consumer A wants changed values for Col1, Col2 & Col4, whereas Consumer B wants changed values for Col1, Col3 & Col5
 
If we have a way of obtaining all the differences between a row in MyTable & its historic row in MyTable_Hist, and storing that in another table, System A will only pick up the changes when the columns of interest to it change, and similarly with System B, when the columns of interest to it change.
  • Guest
    Reply
    |
    Dec 14, 2018

    Hi,

    you did not describe how you want the difference returned or presented in your "idea" so it is hard it image what makes sense for you. I agre with Paul Vernon that SQL would solve your problem already today. Instead of muliple views you could have only one and return the names of the columns that have changed so it would be useable for all your consumers.

  • Guest
    Reply
    |
    Dec 14, 2018

    Humm, looks like you can;t edit your comments in Aha!  :-(   I should have said "Also, I can't see why you can't do what you ask with a simple view.

  • Guest
    Reply
    |
    Dec 14, 2018

    Thanks for your detailed response.

    I'm not asking for multiple system history tables for a base table.

    We're trying to enable self-serve data provisioning for multiple data consumers, who each may need changes to different data elements, WITHOUT the need to build multiple objects/hard-code the fields for each consumer.

    Let me try explain better:

    Say we have a Employee table that tracks employee history, as a bitemporal table, with the following fields:
    EmployeeID
    System temporal columns
    Application temporal columns
    FirstName
    LastName
    EmailAddress
    BusinessPhone
    HomePhone
    OfficeLocation
    OfficeDesk
    EmployeeStatus
    HireDate
    TerminationDate

    For this data, say Consumer A is only interested in changes to FirstName, LastName, and EmailAddress, whereas Consumer B is interested in changes to FirstName, LastName, BusinessPhone, and HomePhone.

    We don't want to create a separate view per consumer since this object in reality has over 100 fields and over 30-40 consumers, each with different subset of columns that they're looking for changes in.

    Since Temporal tables have change information at a row-level, we were trying to see if there's a way to utilize this information to know what has changed at a field-level, in a dynamic manner, for consumers to look for changes to the fields that they're interested in.

  • Guest
    Reply
    |
    Dec 14, 2018

    I'm not sure that this is a very common requirement. Are you asking to be able to have more than 1 SYSTEM HISTORY TABLE for a given base table, and with a user definable sub-set of columns triggering historical capture for each history table?  Again, does not sound very widely applicable. Have you got some more back-ground into this request? It is a mult-tennency thing? 

    Also, I can't see why you can do what you ask with a simple view.  It might not be a performant at query time as separate history tables, but might well be sufficient for your needs.  See below for an example

    Note that I use a join on SYS_START below (i.e. I ignore and TRANSACTION START ID complexity), but you could use LAG() and sort ordering instead...  (I also ignore NULL changes, but again you could add that)

     

    CREATE TABLE H
    (
     col1 int not null, col2 int, col3 int, col4 int, col5 int, col6 int,
     sys_start    TIMESTAMP(12) NOT NULL GENERATED ALWAYS AS ROW BEGIN IMPLICITLY HIDDEN,
     sys_end      TIMESTAMP(12) NOT NULL GENERATED ALWAYS AS ROW END IMPLICITLY HIDDEN,
     ts_id        TIMESTAMP(12) NOT NULL GENERATED ALWAYS AS TRANSACTION START ID IMPLICITLY HIDDEN,
     PERIOD SYSTEM_TIME (sys_start, sys_end)
    )
    organize by row;
    CREATE TABLE HH LIKE H organize by row;
    ALTER TABLE H ADD VERSIONING USE HISTORY TABLE HH;
    INSERT INTO H VALUES (1,2,3,4,5,6);
    UPDATE H SET COL4 = COL4 + 1;
    UPDATE H SET COL4 = COL4 + 1, COL5 = 8;

    CREATE VIEW SYSTEM_A_CHANGES AS
    SELECT H.COL1, H2.COL1 AS PREV_COL1
    ,      H.COL2, H2.COL2 AS PREV_COL2
    ,      H.COL4, H2.COL4 AS PREV_COL4
    FROM H  FOR SYSTEM_TIME BETWEEN '0001-01-01' AND '9999-01-01'
    JOIN
         H FOR SYSTEM_TIME BETWEEN '0001-01-01' AND '9999-01-01'  AS H2
    ON
        H.sys_start = H2.sys_end
    WHERE
        H.COL1 <> H2.COL1
    OR  H.COL2 <> H2.COL2
    OR  H.COL4 <> H2.COL4
    ;