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

  • Home
  • SEARCH
  • 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 211855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:07:59+00:00 2026-05-11T18:07:59+00:00

referring to this question , I’ve decided to duplicate the tables every year, creating

  • 0

referring to this question, I’ve decided to duplicate the tables every year, creating tables with the data of the year, something like, for example:

orders_2008
orders_2009
orders_2010
etc...

Well, I know that probably the speed problem could be solved with just 2 tables for each element, like orders_history and order_actual, but I thought that once the handler code is been wrote, there will be no difference.. just many tables.

Those tables will have even some child with foreign key;
for example the orders_2008 will have the child items_2008:

CREATE TABLE orders_2008 (
    id serial NOT NULL,
    code character(5),
    customer text
);

ALTER TABLE ONLY orders_2008
    ADD CONSTRAINT orders_2008_pkey PRIMARY KEY (id);

CREATE TABLE items_2008 (
    id serial NOT NULL,
    order_id integer,
    item_name text,
    price money
);

ALTER TABLE ONLY items_2008
    ADD CONSTRAINT items_2008_pkey PRIMARY KEY (id);

ALTER TABLE ONLY items_2008
    ADD CONSTRAINT "$1" FOREIGN KEY (order_id) REFERENCES orders_2008(id) ON DELETE CASCADE;

So, my problem is: what do you think is the best way to replicate those tables every 1st january and, of course, keeping the table dependencies?

A PHP/Python script that, query after query, rebuild the structure for the new year (called by a cron job)?
Can the PostgreSQL’s functions be used in that way?
If yes, how (an little example will be nice)

Actually I’m going for the first way (a .sql file containing the structure, and a php/python script loaded by cronjob that rebuild the structure), but i’m wondering if this is the best way.

edit: i’ve seen that the pgsql function CREATE TABLE LIKE, but the foreigns keys must be added in a second time.. or it will keep the new tables referencied tot he old one.

  • 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-05-11T18:07:59+00:00Added an answer on May 11, 2026 at 6:07 pm

    PostgreSQL has a feature that lets you create a table that inherits fields from another table. The documentation can be found in their manual. That might simplify your process a bit.

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

Sidebar

Ask A Question

Stats

  • Questions 242k
  • Answers 242k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Two words: Sinatra and ERB (For lightweight sites, at least).… May 13, 2026 at 7:42 am
  • Editorial Team
    Editorial Team added an answer MSDN - ASP.NET Configuration File Syntax May 13, 2026 at 7:42 am
  • Editorial Team
    Editorial Team added an answer Given that a year simply needs to be a valid… May 13, 2026 at 7:42 am

Related Questions

referring to this question , I've decided to duplicate the tables every year, creating
Referring to this question , how can i get the current page size in
This is a followup to this question . I seem to be stuck on
I have a feeling I may already know the answer to this question, but
In responses to this question, KM said if you are on or above SQL

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.