Giter Site home page Giter Site logo

Comments (3)

ovhemert avatar ovhemert commented on June 28, 2024 2

There might be a bit of a confusion here in the arguments passed to the trigger.

Basic creation of the trigger as per examples is done with 3 arguments which map to TG_ARG[0] - TG_ARG[2].
The 3rd argument here is causing the lower range to be left out when set to false using this condition.
This is the result of your example:

create trigger test_table_versioning_trigger
before insert or update or delete on test_table
for each row EXECUTE procedure versioning(
  'sys_period', 'test_table_history', false
);

During the creation of the trigger there is also a 4th argument (TG_ARG[3]) that controls the Ignore updates without actual change. That parameter is by default set to false, but can be set to true during creation of the trigger. In the sql-file this maps to the ignore_unchanges_values on line 54.

CREATE TRIGGER versioning_trigger
BEFORE INSERT OR UPDATE OR DELETE ON subscriptions
FOR EACH ROW EXECUTE PROCEDURE versioning(
  'sys_period', 'subscriptions_history', true, true
);

This means that if you want to use the functionality to ignore unchanged values, please add the 4th parameter (set to true) to you trigger creation.

from temporal_tables.

simoneb avatar simoneb commented on June 28, 2024

Can you provide a repro please?

from temporal_tables.

kilterskjalg avatar kilterskjalg commented on June 28, 2024

Try this:

BEGIN;
create table test_table (
  id integer primary key generated by default as identity,
  test text,
  sys_period tstzrange not null default tstzrange(CURRENT_TIMESTAMP, null)
);

create table test_table_history (LIKE test_table);

create trigger test_table_versioning_trigger
before insert or update or delete on test_table
for each row EXECUTE procedure versioning(
  'sys_period', 'test_table_history', false
);

insert into test_table(test) values ('hello');
COMMIT;

select pg_sleep(5);
delete from test_table;
select * from test_table_history; -- observe only one timestamp in time range

-- drop table test_table;
-- drop table test_table_history;

from temporal_tables.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.