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 <ja...@xnet.co.nz> wrote:
> On 2011-07-06, Kevin Crain <kevin.cra...@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
>

-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql

Reply via email to