Re: Error Trapping -duplicate keys

From: Ludwig Lim <lud_nowhere_man(at)yahoo(dot)com>
To: "Steven D(dot) Smith" <sds07(at)health(dot)state(dot)ny(dot)us>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Error Trapping -duplicate keys
Date: 2002-07-02 12:00:21
Message-ID: 20020702120021.42065.qmail@web40004.mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice


Steven:

Try using a
select count(*)
from <table>
where <field of the primary key>=<key to be
inserted>.

to check the count of the data.
if count is zero insert else update.

--- "Steven D. Smith" <sds07(at)health(dot)state(dot)ny(dot)us>
wrote:
> Help:
>
> I'm using Perl to insert data from a log file, what
> I am doing is this
> (Pseudocode):
>
> If NOT (INSERT INTO myTABLE)
> THEN UPDATE myTABLE
> endIf
>
> Now the code I have works except I get a console
> message:
>
> DBD::Pg::st execute failed: ERROR: Cannot
> insert a duplicate key
> into unique index visitor_pkey at ./inslog.pl line
> 147, <> chunk 4.
>
> So, my question is how to I trap this error, keep it
> from being display as
> it is not really an error if the insert fails?

ludwig.

__________________________________________________
Do You Yahoo!?
Sign up for SBC Yahoo! Dial - First Month Free
http://sbc.yahoo.com

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Tom Lane 2002-07-02 13:45:10 Re: Error Trapping -duplicate keys
Previous Message Steven D. Smith 2002-07-02 11:40:37 Error Trapping -duplicate keys