Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id B77F41337B80 for ; Thu, 14 Apr 2011 10:24:59 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 00223-06 for ; Thu, 14 Apr 2011 13:24:01 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-qw0-f46.google.com (mail-qw0-f46.google.com [209.85.216.46]) by mail.postgresql.org (Postfix) with ESMTP id 720641337B9C for ; Thu, 14 Apr 2011 10:23:59 -0300 (ADT) Received: by qwk3 with SMTP id 3so868881qwk.19 for ; Thu, 14 Apr 2011 06:23:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:subject:date:user-agent:cc:references :in-reply-to:mime-version:content-type:content-transfer-encoding :message-id; bh=nNhZCvRi2U0mLaI8j6cgPoS2ZCV6UEBTemuaJcH+QQg=; b=lL5atBVqWf4WlGF9BecBEj1niOjOeKqQIwByhFtE4yo96GTz2gyGYN8ZO0SJalfQJC c9JMOZqkI7jFvWn+z17I1k0ceE87zlIS8FBWoyiNpwnMKXxJHC6Uzenzfgb5HlNJphVM ObHcQiBHvi1VC02U5RlaoIHwEP+iXV3Pmqha8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:subject:date:user-agent:cc:references:in-reply-to :mime-version:content-type:content-transfer-encoding:message-id; b=h+E11KGkDo1Rl7/bFxpltLEZPk7qn4qREySnEJPawMriGDUXtFYIpqir+zaSDJtuNf tlhx6RZXYzaTXkFqB8r9lcY99X41R3vogjccwtO+mE7Jy28Ix3sEHqheHl566swuwUOp JW4BrhtdbpZU65hDHTNynwz/9eamXEQgwJkdk= Received: by 10.224.27.20 with SMTP id g20mr506133qac.15.1302787439668; Thu, 14 Apr 2011 06:23:59 -0700 (PDT) Received: from tucker.localnet (c-24-17-164-54.hsd1.wa.comcast.net [24.17.164.54]) by mx.google.com with ESMTPS id c27sm1152396qck.22.2011.04.14.06.23.57 (version=SSLv3 cipher=OTHER); Thu, 14 Apr 2011 06:23:58 -0700 (PDT) From: Adrian Klaver To: pgsql-sql@postgresql.org Subject: Re: Get id of a tuple using exception Date: Thu, 14 Apr 2011 06:23:54 -0700 User-Agent: KMail/1.13.5 (Linux/2.6.32-30-generic; KDE/4.4.5; i686; ; ) Cc: f vf References: In-Reply-To: MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-15" Content-Transfer-Encoding: 7bit Message-Id: <201104140623.55068.adrian.klaver@gmail.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.889 tagged_above=-5 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, T_TO_NO_BRKTS_FREEMAIL=0.01 X-Spam-Level: X-Archive-Number: 201104/18 X-Sequence-Number: 35265 On Thursday, April 14, 2011 3:56:51 am f vf wrote: > Hello, > i'm using a pl/sql procedure and I prevent inserting duplicate tuples using > an exception for example: > > BEGIN > INSERT INTO "Triples"(id, subject, predicate, "object") > VALUES (id, sub_i, pred_i, obj_i); > * EXCEPTION WHEN unique_violation THEN > --do something. > > *In some cases I have interest in getting the id of the tuple that was > already in the table when the exception is triggered. Is there a way for > the EXCEPTION to return that id instead of using a select to know wich was > the id of the triple already existing in the table? If the id is the PRIMARY KEY then it would be the same as the id you tried to INSERT correct? > > Thanks, > Filipe -- Adrian Klaver adrian.klaver@gmail.com