Re: interesting sequence
От | Kevin Crain |
---|---|
Тема | Re: interesting sequence |
Дата | |
Msg-id | CADwm0ah=EBJduNo8eCY+yf-KwUT1bCFwozQ7xHS3PPz-hB5=2w@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: interesting sequence (Jasen Betts <jasen@xnet.co.nz>) |
Список | 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 по дате отправления: