Re: Error Trapping -duplicate keys - Mailing list pgsql-novice

From Ludwig Lim
Subject Re: Error Trapping -duplicate keys
Date
Msg-id 20020702120021.42065.qmail@web40004.mail.yahoo.com
Whole thread Raw
In response to Error Trapping -duplicate keys  ("Steven D. Smith" <sds07@health.state.ny.us>)
Responses Re: Error Trapping -duplicate keys  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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@health.state.ny.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



pgsql-novice by date:

Previous
From: "Steven D. Smith"
Date:
Subject: Error Trapping -duplicate keys
Next
From: Tom Lane
Date:
Subject: Re: Error Trapping -duplicate keys