Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id B6AFC2E0081 for ; Tue, 26 Feb 2008 16:03:27 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 05425-01-7 for ; Tue, 26 Feb 2008 16:03:15 -0400 (AST) X-Greylist: delayed 00:13:47.573097 by SQLgrey-1.7.5 Received: from mdpserv.comsquared.com (host106.milner.com [199.72.226.106]) by postgresql.org (Postfix) with ESMTP id 2B9692E026E for ; Tue, 26 Feb 2008 15:43:34 -0400 (AST) Received: from EROUSE (erouse.ntc2s.comsquared.com [10.82.60.20]) by mdpserv.comsquared.com (8.13.6+Sun/8.13.6) with ESMTP id m1QJV67N029214 for ; Tue, 26 Feb 2008 14:31:06 -0500 (EST) From: "Edward W. Rouse" To: Subject: Re: duplicate key violates unique constraint Date: Tue, 26 Feb 2008 14:29:45 -0500 Message-ID: <0b0301c878ad$f1353310$143c520a@ntc2s.comsquared.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0B04_01C87884.085F2B10" X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.6626 Importance: Normal In-Reply-To: <47C44DA9.A3DD.0030.0@indicator.be> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1914 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.102 tagged_above=0 required=5 tests=AWL=0.101, HTML_MESSAGE=0.001 X-Spam-Level: X-Archive-Number: 200802/214 X-Sequence-Number: 30305 This is a multi-part message in MIME format. ------=_NextPart_000_0B04_01C87884.085F2B10 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Could it be that the insert statement itself is the problem? What does = the table look like? =20 =20 Edward W. Rouse =20 -----Original Message----- From: pgsql-sql-owner@postgresql.org = [mailto:pgsql-sql-owner@postgresql.org] On Behalf Of Bart Degryse Sent: Tuesday, February 26, 2008 11:35 AM To: pgsql-sql@postgresql.org; Shavonne Marietta Wijesinghe Subject: Re: [SQL] duplicate key violates unique constraint Shavonne, You will probably always find someone on the list who will answer your = questions, but you really should read the manual too! In this case you could have found the answer by reading http://www.postgresql.org/docs/8.2/static/plpgsql-control-structures.html= #PLPGSQL-ERROR-TRAPPING >>> "Shavonne Marietta Wijesinghe" = 2008-02-26 17:05 >>> Thank you. I tried as you said. But i get a ERROR: syntax error at or = near=20 "INSERT" at character 9 BEGIN INSERT INTO my_shevi values ('a', 4, 2, 2); EXCEPTION WHEN unique_violation THEN INSERT INTO my_shevi values ('a', 5, 2, 2); END; I don't see anything wrong with the code.. Shavonne ----- Original Message -----=20 From: "Teemu Torma" To: Sent: Tuesday, February 26, 2008 4:17 PM Subject: Re: [SQL] duplicate key violates unique constraint > On Tuesday 26 February 2008, Shavonne Marietta Wijesinghe wrote: >& gt; During an "INSERT INTO" I get an "Error - duplicate key violates >> unique constraint...." >> >> Is there any way, that i can test the error. Something like this?? >> >> IF error =3D "duplicate key violates unique constraint" then >> =C2 =C2 do something >> else >> =C2 =C2 insert into >> end if > > insert into ...; > exception when unique_violation then > do something; > > Teemu > > ---------------------------(end of = broadcast)--------------------------- > TIP 5: don't forget to increase your free space map settings=20 ---------------------------(end of broadcast)--------------------------- TIP 5: don't forget to increase your free space map settings ------=_NextPart_000_0B04_01C87884.085F2B10 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Message
Could it be that the insert = statement itself=20 is the problem? What does the table look like?
 
 

Edward W. Rouse

 

-----Original Message-----
From:=20 pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org] = On=20 Behalf Of Bart Degryse
Sent: Tuesday, February 26, 2008 = 11:35=20 AM
To: pgsql-sql@postgresql.org; Shavonne Marietta=20 Wijesinghe
Subject: Re: [SQL] duplicate key violates unique=20 constraint

Shavonne,
You will probably always find someone on the list who will answer = your=20 questions, but you really should read the manual too!
In this case you could have found the answer by reading
http://www.postgresql.org/docs/8.2/stati= c/plpgsql-control-structures.html#PLPGSQL-ERROR-TRAPPING

>&= gt;>=20 "Shavonne Marietta Wijesinghe" <shavonne.marietta@studioform.it> = 2008-02-26 17:05 >>>
Thank you. I tried as you said. But i = get a=20 ERROR:  syntax error at or near
"INSERT" at character=20 9

BEGIN
INSERT INTO my_shevi values ('a', 4, 2,=20 2);
EXCEPTION
WHEN unique_violation THEN
INSERT INTO my_shevi = values=20 ('a', 5, 2, 2);
END;

I don't see anything wrong with the=20 code..

Shavonne

----- Original Message -----
From: = "Teemu=20 Torma" <teemu@torma.org>
To:=20 <pgsql-sql@postgresql.org>
Sent: Tuesday, February 26, 2008 = 4:17=20 PM
Subject: Re: [SQL] duplicate key violates unique=20 constraint


> On Tuesday 26 February 2008, Shavonne = Marietta=20 Wijesinghe wrote:
>& gt; During an "INSERT INTO" I get an = "Error -=20 duplicate key violates
>> unique=20 constraint...."
>>
>> Is there any way, that i can = test the=20 error. Something like this??
>>
>> IF error =3D = "duplicate key=20 violates unique constraint" then
>> =C2 =C2 do = something
>>=20 else
>> =C2 =C2 insert into
>> end = if
>
> insert=20 into ...;
> exception when unique_violation then
>  = do=20 something;
>
> Teemu
>
>=20 ---------------------------(end of=20 broadcast)---------------------------
> TIP 5: don't forget to = increase=20 your free space map settings =


---------------------------(end of=20 broadcast)---------------------------
TIP 5: don't forget to = increase your=20 free space map settings
------=_NextPart_000_0B04_01C87884.085F2B10--