Re: interesting sequence - Mailing list pgsql-sql

From Kevin Crain
Subject Re: interesting sequence
Date
Msg-id CADwm0ah=EBJduNo8eCY+yf-KwUT1bCFwozQ7xHS3PPz-hB5=2w@mail.gmail.com
Whole thread Raw
In response to Re: interesting sequence  (Jasen Betts <jasen@xnet.co.nz>)
List pgsql-sql
IF this field is unique you shouldn't get duplicates from a function;
the transaction will either succeed or fail; the beauty of a function
is that you can return an error message.  I personally prefer to
handle errors at the application level, but if you have admins running
ad-hoc queries on the database level doing inserts then you definitely
do need to handle that properly.  Triggers are handy in that regard.
You can do loops to check for collisions...I haven't done that so
don't know the best way to code that though.

On Wed, Jul 6, 2011 at 5:28 AM, Jasen Betts <jasen@xnet.co.nz> wrote:
> On 2011-07-06, Kevin Crain <kevin.crain1@gmail.com> wrote:
>> That's why you need to do this inside a function.  Basically just make
>> an insert function for the table and have it calculate the count and
>> do the insert in one transaction.
>
> you will still get duplicates, so include code in the function to
> retry if there is an error.
>
> --
> ⚂⚃ 100% natural
>
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
>


pgsql-sql by date:

Previous
From: Wes James
Date:
Subject: combining strings to make a query
Next
From: Kevin Crain
Date:
Subject: Re: Max column number.