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 8818753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:11:04+00:00 2026-06-14T05:11:04+00:00

I’m using PostgreSQL and I need to have two or more tables that are

  • 0

I’m using PostgreSQL and I need to have two or more tables that are mostly synchronized in my database, such that an Add/Delete/Update to a row in sub table is made to the master table.

I’m not sure if trigger can be used in this situation because in my situation the sub table may be truncated and load in with new set of data

Any idea how to implement that ?

Example:

Employee_Sub1:
 id    name    version
+------+-------+--------+
 101    John     1
 102    David    1
 105    Azi      1

Employee_Sub2:
 id    name    version
+------+-------+--------+
 101    John     1
 102    DavidX   2       <- Sub2 having updated value for id 102
 105    Azi      1
 107    Marry    1

Employee_Sub3:
 id    name    version
+------+-------+--------+
 101    John    1
 105    Azi     1
 110    devil   1       <- Sub3 having new row of data

The Employee_Final table shall look like this :

Employee_Final:
 id    name    version
+------+-------+--------+
 101    John    1
 102    DavidX  2
 105    Azi     1
 107    Marry   1
 110    devil   1
  • 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-14T05:11:05+00:00Added an answer on June 14, 2026 at 5:11 am

    I think you’re looking for triggers; see PL/PgSQL trigger procedures for how to implement them in PL/PgSQL. Use AFTER INSERT OR UPDATE OR DELETE triggers on each of Employee_Sub1, Employee_Sub2, and Employee_Sub3 to propagate their changes to Employee_Final.

    There’s also a bit of a table inheritance feel about this question, but I’m not sure inheritance is a good fit.

    Usually when you’re changing IDs you use ON UPDATE CASCADE foreign key references, but that won’t work here because you need it reversed, where the PK gets updated when you change the FK. That’s another job for a trigger; you have to compare the NEW and OLD record IDs and update the master table if the ID has changed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have thousands of HTML files to process using Groovy/Java and I need to
I have a reasonable size flat file database of text documents mostly saved in
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I have a view passing on information from a database: def serve_article(request, id): served_article

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.