Re: insert fail gracefully if primary key already exists - Mailing list pgsql-novice

From Alessandro Gagliardi
Subject Re: insert fail gracefully if primary key already exists
Date
Msg-id CAAB3BBJsaPRY-zg-BAs6wb=o4c4Qr65NLW3usk-tSb2pSgxWFg@mail.gmail.com
Whole thread Raw
In response to Re: insert fail gracefully if primary key already exists  (Bartosz Dmytrak <bdmytrak@eranet.pl>)
Responses Re: insert fail gracefully if primary key already exists
Re: insert fail gracefully if primary key already exists
List pgsql-novice
Sorry I wasn't clear. The application is written in Python. It services requests that may go to an external API or to our production database (which is Mongo). I should add that we have a somewhat unusual situation in which we have two parallel databases: MongoDB for OLTP and newer PostgreSQL for OLAP. Because Postgres is only consuming, it would waste precious cycles to have the client check to see if a record already exists in Postgres before trying to insert it. I'd rather let Postgres deal with that (which it does well enough anyway with my primary key constraints). My Postgres instance is hosted by Heroku and they provide me with a log which is currently being spammed by these "duplicate key value violates unique constraint" errors making it impossible to see if there are other errors I need to be paying more attention to. 

On Sat, Feb 11, 2012 at 12:08 AM, Bartosz Dmytrak <bdmytrak@eranet.pl> wrote:
Could You provide more details?
PostgreSQL does not allow cross database queries.


Regards,
Bartek


2012/2/10 Alessandro Gagliardi <alessandro@path.com>
I have a situation where I am gradually filling in a table from another database as the need requires. As it currently is, whenever a record comes up, it tries to insert it into my database. If the row is already there, the primary key collides and the insert fails. And that's fine except that it makes for a really cluttered log (making it hard to find errors that I really do need to pay attention to). I'm wondering if there's a better (i.e. cleaner, but possibly also more efficient) way to do this. 

Thoughts?

Thank you in advance,
-Alessandro


pgsql-novice by date:

Previous
From: Merlin Moncure
Date:
Subject: Re: Using libpq 8.4 with Postgre 9.1
Next
From: Bartosz Dmytrak
Date:
Subject: Re: insert fail gracefully if primary key already exists