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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:43:55+00:00 2026-05-27T02:43:55+00:00

I come from a mysql background where if I want to insert a record

  • 0

I come from a mysql background where if I want to insert a record I can use an INSERT IGNORE command so that I can just bung rows in and if there’s a conflict just ignore it.

Now, with a Django project I’m working on I’m using postgresql, and issue multiple saves in a loop. However, I think if I get an IntegrityError (which I’m ignoring, see code below) then I lose loads of objects that I’m trying to insert.. how should I fix this:

for thing in things:
    try:
        #potentially dangerous save..
        obj = Thing(stuff=10)
        obj.save()
    except IntegrityError:
        pass

If say, on the 5th go round the loop an IntegrityError happens, which objects will get inserted into the DB?

  • 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-27T02:43:56+00:00Added an answer on May 27, 2026 at 2:43 am

    It will depend on how you manage your transaction.

    On Postgres if one of query in transaction fails all subsequent query will also fail with error “current transaction is aborted, queries ignored until end of transaction block”.

    To deal with it you should use transaction.savepoint_rollback in an except block.

    Please refer to Django doc Handling exceptions within PostgreSQL transactions

    It gives the next example

    a.save() # Succeeds, and never undone by savepoint rollback
    try:
        sid = transaction.savepoint()
        b.save() # Could throw exception
        transaction.savepoint_commit(sid)
    except IntegrityError:
        transaction.savepoint_rollback(sid)
    c.save() # Succeeds, and a.save() is never undone
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I come from a mainly PHP background and make good use of the Apache
I come from a SQL Server background and thought that it might mean it
I have a PHP application that I want to switch from MySQL to Cache
I come from a linux/apache/php/mysql background. For my current project, I am forced to
I've just started getting into Node.js. I come from a PHP background, so I'm
How do I query within the results that have come from a previous MySQL
I come from a MySQL background and am trying to wrap my head around
I come from MySQL background and I am trying to learn MongoDB. I have
I come from a Java background, where packages are used, not namespaces. I'm used
I come from the Microsoft world (and I come in peace). I want to

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.