Errors attempting to insert duplicate values

From: "Bryan White" <bryan(at)arcamax(dot)com>
To: "pgsql-general" <pgsql-general(at)postgreSQL(dot)org>
Subject: Errors attempting to insert duplicate values
Date: 2000-06-05 19:37:48
Message-ID: 006b01bfcf25$87ca87c0$2dd260d1@arcamax.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I have a table with a unique index. When I go to insert a new value into
the table my code does not know if the record is already there. To me there
are two choices:

1) Do a select for the record and insert only if not found.

2) Do a blind insert and relay on the unique index to fail the insert if
there is a duplicate.

I have chosen to do #2 and it has worked well for a long time. It seems
better to keep the number of database interactions to a minimum. The only
problem is everytime a duplicate insertion is attempted an error is printed
in the log file.

The anal-retentive part of my personality is bugged by this. What do other
people think? Is the technique legitimate and should the database be
reporting errors for legitimate operations?

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Mihai Gheorghiu 2000-06-05 19:46:16 Table
Previous Message Brook Milligan 2000-06-05 19:11:13 interaction between rules, functions and permissions