Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7926933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:03:08+00:00 2026-06-03T19:03:08+00:00

I wanted to use timetravel function (F.39. spi, PostgreSQL 9.1 Documentation) in my application,

  • 0

I wanted to use timetravel function (F.39. spi, PostgreSQL 9.1 Documentation) in my application, however it doesn’t seem to work properly for me. With inserting rows into table everything works just fine, I get start and stop date properly, but when I’m trying to update those rows postgres gives me error about violating of PRIMARY KEY constraint. He’s trying to insert a tuple with the same primary id as previous tuple…

It’s insane to remove primary key constraints from all tables in the database but it’s the functionality I need. So maybe you have some expierience with timetravel?

Any sort of help will be appreciated. Thanks in advance.

DDL:

CREATE TABLE cities
(
  city_id serial NOT NULL, 
  state_id integer, 
  name character varying(80) NOT NULL,
  start_date abstime,
  stop_date abstime,
  CONSTRAINT pk_cities PRIMARY KEY (city_id ),
  CONSTRAINT fk_cities_states FOREIGN KEY (state_id)
      REFERENCES states (state_id) MATCH SIMPLE
      ON UPDATE CASCADE ON DELETE NO ACTION
)
WITH (
  OIDS=FALSE
);



-- Trigger: time_travel on cities

-- DROP TRIGGER time_travel ON cities;

CREATE TRIGGER time_travel
  BEFORE INSERT OR UPDATE OR DELETE
  ON cities
  FOR EACH ROW
  EXECUTE PROCEDURE timetravel('start_date', 'stop_date');

STATEMENT GIVEN:

INSERT INTO cities(
            state_id, name)
    VALUES (20,'Paris');

and that’s ok. I get start_date and stop_date.
But by:

UPDATE cities SET name='Rome' WHERE name='Paris'

I get error- described earlier.

Schema of states

-- Table: states

-- DROP TABLE states;

CREATE TABLE states
(
  state_id serial NOT NULL, -- unikatowy numer wojewodztwa
  country_id integer, -- identyfikator panstwa, w ktorym znajduje sie wojewodztwo
  name character varying(50), -- nazwa wojewodztwa
  CONSTRAINT pk_states PRIMARY KEY (state_id ),
  CONSTRAINT uq_states_state_id UNIQUE (state_id )
)
WITH (
  OIDS=FALSE
);

Unfortunately,as a new user I’m not allowed to post images here.
You can see them there:

Sample data from table cities: korpusvictifrew.cba.pl/postgres_cities.png

Sample data from table states: korpusvictifrew.cba.pl/states_data.png

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T19:03:09+00:00Added an answer on June 3, 2026 at 7:03 pm

    Time travel converts an UPDATE into an UPDATE of the old record’s stop_date and an INSERT of a new one with the changed data plus an infinity stop_date. You can’t have more than one record for city_id due to pk_cities. The time travel triggers do not allow you to break that requirement.

    You cannot use this:

    CONSTRAINT pk_cities PRIMARY KEY (city_id )
    

    You must use this

    CONSTRAINT pk_cities PRIMARY KEY (city_id, stop_date)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wanted to use the currentStateChange event in my application but whatever code being
I wanted to use memcached for my C++ application. To do that I need
I wanted to use a native Dll in my C# .net application as this:
I wanted to use MongoDB in my Grails application and also Spring Security. I
I have an application with a Java back-end. I wanted to use Drupal CMS
I wanted to use count() function in ColdFusion Query object. Here is my code
I wanted to use the php filer_var function but it's returning a wrong result,
I wanted to use code like this in my Zend Framework project: public function
I wanted to use a scriplet inside a java script function. I wanted to
i wanted to use SQLite with .net application. It only works if the DLL

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.