Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 982841337BE4 for ; Thu, 14 Apr 2011 11:32:25 -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 41379-08 for ; Thu, 14 Apr 2011 14:32:16 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-qy0-f181.google.com (mail-qy0-f181.google.com [209.85.216.181]) by mail.postgresql.org (Postfix) with ESMTP id 994431337BCF for ; Thu, 14 Apr 2011 11:32:14 -0300 (ADT) Received: by qyg14 with SMTP id 14so1080782qyg.19 for ; Thu, 14 Apr 2011 07:32:15 -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=i0hHTy/g4iTXehfe/5cWalAhh9Uibi7fdAQEwn2a26Q=; b=Q/ucHzMTb/fCEcjf8ZSRbYTPC7nHb/zieDqHIlBUJ7tg8GblZEX5oulXWpiCVjAgzO +mVgoyogSp78XvK5LlH2ElujvgLIE228uoYGfD/RYl258IsQZxmmqzsGorW/iMhhgMgI 3GriKvlcoXx5d3p4CSo9y2Alm1W2l8yu0CnVY= 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=aa2xK5b0zCq4bFrnisEB/Dh8M/erXuvxcSyuW8Qb0iNpuK+/Z+U/tA4zaLidLx/ihH 19F3X9pAppbXT9DBlpp3CLA4h4No1NYVIJPp4mWUkRBJ5+FcWtUgm00l1wMumHzJg/F3 RSQEHAaW4vTc1ymHhV6i1oz7A9Os1y1NJl+0I= Received: by 10.52.0.229 with SMTP id 5mr1123690vdh.271.1302791534830; Thu, 14 Apr 2011 07:32:14 -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 h23sm988533vbz.21.2011.04.14.07.32.12 (version=SSLv3 cipher=OTHER); Thu, 14 Apr 2011 07:32:13 -0700 (PDT) From: Adrian Klaver To: f vf Subject: Re: Get id of a tuple using exception Date: Thu, 14 Apr 2011 07:32:08 -0700 User-Agent: KMail/1.13.5 (Linux/2.6.32-30-generic; KDE/4.4.5; i686; ; ) Cc: pgsql-sql@postgresql.org References: <201104140623.55068.adrian.klaver@gmail.com> In-Reply-To: MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-15" Content-Transfer-Encoding: 7bit Message-Id: <201104140732.09311.adrian.klaver@gmail.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.899 tagged_above=-5 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001 X-Spam-Level: X-Archive-Number: 201104/19 X-Sequence-Number: 35266 On Thursday, April 14, 2011 6:50:57 am f vf wrote: > No, the id is nextval( 'triples_seq'), if I do nothing, so its something > like: > BEGIN > INSERT INTO "Triples"(id, subject, predicate, "object") > VALUES (nextval( 'triples_seq'), sub_i, pred_i, > obj_i); EXCEPTION WHEN unique_violation THEN > --do something. > > The unique constraint is applyied to the subject, predicate and "object" > fields. So, if I try to insert anything that has these 3 fields equal to > any tuple that already exists in the table I want to get the id of the > original tuple. > To your original question I am not aware of a way of returning the id of the offending tuple, other than through a SELECT. -- Adrian Klaver adrian.klaver@gmail.com