From: Adrian Klaver <adrian.klaver@gmail.com>
To: f vf <fvalentef@gmail.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Get id of a tuple using exception
Date: Thu, 14 Apr 2011 07:32:08 -0700
Message-ID: <201104140732.09311.adrian.klaver@gmail.com> (raw)
In-Reply-To: <BANLkTimrMfAqD6o3s3=3pToj-TWS3vu6_w@mail.gmail.com>
References: <BANLkTik0fUKBcdYEnFeLczA0e6Gmt-3D=g@mail.gmail.com>
<201104140623.55068.adrian.klaver@gmail.com>
<BANLkTimrMfAqD6o3s3=3pToj-TWS3vu6_w@mail.gmail.com>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: adrian.klaver@gmail.com, fvalentef@gmail.com
Subject: Re: Get id of a tuple using exception
In-Reply-To: <201104140732.09311.adrian.klaver@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox