xocolatl / periods

PERIODs and SYSTEM VERSIONING for PostgreSQL

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

System Versioning on table with dropped columns contains corrupted data in history table

MaryHal opened this issue · comments

Hi, I'm trying to migrate my postgresql 11 database from temporal_tables to periods, and I ran into this issue.

From the looks of it, it kind of makes sense how this could happen since dropped columns in postgres don't just disappear. Is this a known limitation? I could always recreate the source table, but I'd like to make sure there's nothing I'm missing.

Minimal script:

CREATE TABLE test (
    test_id int GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
    value VARCHAR NOT NULL
);

ALTER TABLE test
    DROP COLUMN value;

ALTER TABLE test
    ADD COLUMN value2 varchar NOT NULL;

INSERT INTO test (value2)
    VALUES ('hello'), ('world');

SELECT periods.add_system_time_period ('test');
SELECT periods.add_system_versioning ('test');


UPDATE test
SET value2 = 'goodbye'
WHERE test_id = 2;

Expected:

SELECT * FROM test_with_history;
test_id | value2  | system_time_start             | system_time_end               |
--------|---------|-------------------------------|-------------------------------|
      1 | hello   |                     -infinity |                      infinity |
      2 | goodbye | 2019-12-04 18:04:55.825756-08 |                      infinity |
      2 | world   |                     -infinity | 2019-12-04 18:04:55.825756-08 |

Actual:

test_id | value2  | system_time_start             | system_time_end |
--------|---------|-------------------------------|-----------------|
      1 | hello   |                     -infinity |        infinity |
      2 | goodbye | 2019-12-04 18:04:55.825756-08 |        infinity |
      2 |  [NULL] | 2004-06-09 20:21:18.209996-07 |       -infinity |

Hi. Thank you for your interest in this extension!

This look like a bug to me, I will look into it quickly.

That took me longer than expected to fix. Thank you for your patience. I will tag a new release soon.

Thanks! I look forward to using it 😄