Received: from localhost (unknown [200.46.204.183]) by developer.postgresql.org (Postfix) with ESMTP id D29882E003E for ; Tue, 10 Jun 2008 18:38:54 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 48021-09 for ; Tue, 10 Jun 2008 18:38:48 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from fk-out-0910.google.com (fk-out-0910.google.com [209.85.128.186]) by developer.postgresql.org (Postfix) with ESMTP id BF96F2E0033 for ; Tue, 10 Jun 2008 18:38:51 -0300 (ADT) Received: by fk-out-0910.google.com with SMTP id e30so1774744fke.3 for ; Tue, 10 Jun 2008 14:38:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:cc:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=lkczyNfFOkH+TQQ/sErQPFCMyyzrc1ZNd++TrEZrQIE=; b=N4vzx0KadmS8uXi165EpWLUabtiVGJNsQ9A8jJMrHJs0Rdd5aVx1TkzKIuYwpiil4y +Ph9KNlKGXYIivCsrYZVXUJSwW/EhTeTNp/eKqmb9HHAcbLtBG+ULWRFKPNPoMrGt0CH zTt4EdGciMgqpedfrTriDp2Bi5fe4sQPKpG+s= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=dOPCgMYvczJuMFWADSc+A+5F750P57F5rX0+8j+/hee5EJNHPo5UXC8tX04rND4d1X rv9SG63a2RFLc3ArzMIqmhgBDSpwaXuCM6A4K9oFIneEZj3/jmpYyJF4/5Xy842UW9rQ LFKGRB2QfJk6pf8X9mgL2a3YwL1yYs8EX0Vos= Received: by 10.82.153.5 with SMTP id a5mr375948bue.44.1213133930135; Tue, 10 Jun 2008 14:38:50 -0700 (PDT) Received: by 10.82.184.18 with HTTP; Tue, 10 Jun 2008 14:38:50 -0700 (PDT) Message-ID: <34d269d40806101438k3fe3833k48ff9e0224b1cbee@mail.gmail.com> Date: Tue, 10 Jun 2008 15:38:50 -0600 From: "Alex Hunsaker" To: Dinesh Subject: Re: error handling unique key constraint in pgsql Cc: "Scott Marlowe" , pgsql-admin@postgresql.org In-Reply-To: <484EE821.6090700@mongonet.net> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <484EB14B.4010003@mongonet.net> <484EE821.6090700@mongonet.net> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200806/84 X-Sequence-Number: 29422 On Tue, Jun 10, 2008 at 2:46 PM, Dinesh wrote: > Hi Scott, > > Thanks for your reply. > > Is there a built in exception in pl/pgsql ( similar to oracle's > |DUP_VAL_ON_INDEX ) that I can use? > > I ran into an unique situation a couple of days ago. Procedure that inserts > a new value into unique index column was called at the same time. I even > check if the value exist before inserting, but one of the instance of the > function gave me an unique constraint violation error. > > My code looks like this: > > select into var * from table; > > if not found then > insert into table > values (a); > end if; > | > I would imagine the postgres db would inherently handle situation like this, > but it did not. > > Thanks. See http://www.postgresql.org/docs/8.3/static/plpgsql-control-structures.html#PLPGSQL-ERROR-TRAPPING, specifically example Example 38-1.