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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:21:58+00:00 2026-06-13T00:21:58+00:00

I have a task that to implement a ‘rollback’ (not the usual rollback) function

  • 0

I have a task that to implement a ‘rollback’ (not the usual rollback) function for a batch of entries from different tables. For example:

def rollback(cursor, entries):
    # entries is a dict of such form: 
    # {'table_name1': [id1, id2, ...], 'table_name2': [id1, id2, ...], ...}

I need to delete entries in each table_name. But because these entries may have relationship between so a bit complex. My idea is in several steps:

  1. Find out all columns from all tables that are nullable.
  2. Update all entries set all columns that are nullable to null. After this step there should be no circular depends (if not, i think they can’t be insert into the table)
  3. Find out their depends and make a topological sort.
  4. Delete one by one.

My questions are:

  1. Does the idea make sense?
  2. Has anyone done something similar before? And how?
  3. How to query the meta tables for step 3? coz i’m quite new to postgresql.

Any idea and suggestion would be appreciate.

  • 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-13T00:21:59+00:00Added an answer on June 13, 2026 at 12:21 am

    (1) and (2) are not right. It’s quite likely that there will be columns defined NOT NULL REFERENCES othertable(othercol) – there are in any normal schema.

    What I think you need to do is to sort the foreign key dependency graph to find an ordering that allows you to DELETE, table-by-table, the data you need to remove. Be aware that circular dependencies are possible due to deferred foreign key constraints, so you need to demote/ignore DEFERRABLE INITIALLY DEFERRED constraints; you can temporarily violate those so long as it’s all consistent again at COMMIT time.

    Even then you might run into issues. What if a client used SET CONSTRAINTS to make a DEFERRABLE INITIALLY IMMEDIATE constraint DEFERRED during a transaction? You’d then fail to cope with the circular dependency. To handle this your code must [SET CONSTRAINTS ALL DEFERRED] before proceeding.

    You will need to look at the information_schema or the PostgreSQL-specific system catalogs to work out the dependencies. It might be worth a look at the pg_dump source code too, since it tries to order dumped tables to avoid dependency conflicts. You’ll be particularly interested in the pg_constraint
    catalog, or its information_schema equivalents information_schema.referential_constraints, information_schema.constraint_table_usage and information_schema.constraint_column_usage.

    You can use the either the information_schema or pg_catalog. Don’t use both. information_schema is SQL-standard and more portable, but can be slow to query and doesn’t have all the information pg_catalog contains. On the flip side, pg_catalog‘s schema isn’t guaranteed to remain compatible across major versions (like 9.1 to 9.2) – though it generally does – and its use isn’t portable.

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

Sidebar

Related Questions

i have just received a task to implement a software that paints over pictures
I have a long running task that I need to implement on a webpage.
I have following task: Implement a mechanism that can take any collection of objects
I have to implement a Task subclass that gracefully fails if the broker is
I have to implement a 'global' search/filter function in my application. Each window that
I have such task - to create control that union two controls (DataGrid from
I have a task to implement a 3x3 x-derivative image filter that makes use
Let's say I have a function to perform a small and particular task that
I have a task that runs periodically 10 second. I do some picturebox refreshing
I have a task that takes a rather long time and should run in

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.