pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: tjk@tksoft.com <tk@uno.tksoft.com>
To: frederic.de.leersnijder@pandora.be
Cc: pgsql-sql@hub.org
Subject: Re: [SQL] Can I prevent my sequence to increment if an insert is rejected?
Date: Tue, 20 Jul 1999 12:01:34 -0700 (PDT)
Message-ID: <199907201901.MAA02467@uno.tksoft.com> (raw)
In-Reply-To: <3794A9B3.C323DC4A@pandora.be>

Frederic,

You could (a) do the work inside a transaction, 
or (b) do the insert after you have retrieved
the key and verified it doesn't exist in the table.
I.e. get the nextval from the sequence first and then
do the insert. 

P.S. If a record was inserted with a
used key, wouldn't you want to skip that
sequence value anyway?


Troy

Troy Korjuslommi                Tksoft OY, Inc.
tjk@tksoft.com                  Software Development
                                Open Source Solutions
                                Hosting Services




> 
> Hi,
> 
> when I try to insert a record and it curses with fields with a unique
> key on them my sequence I use for my primary key does increment. How can
> I prevent this from happening?
> 
> 
> Thanks
> Frederic
> 
> 




view thread (5+ messages)  latest in thread

Message-ID: <199907201901.MAA02467@uno.tksoft.com>
Permalink:  ../199907201901.MAA02467@uno.tksoft.com/
Also on:    postgresql.org/message-id/199907201901.MAA02467@uno.tksoft.com

 · 

reply

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: tk@uno.tksoft.com, frederic.de.leersnijder@pandora.be, pgsql-sql@hub.org
  Subject: Re: [SQL] Can I prevent my sequence to increment if an insert is rejected?
  In-Reply-To: <199907201901.MAA02467@uno.tksoft.com>
  References: <3794A9B3.C323DC4A@pandora.be> <199907201901.MAA02467@uno.tksoft.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