D&C Lug - Home Page
Devon & Cornwall Linux Users' Group

[ Date Index ][ Thread Index ]
[ <= Previous by date / thread ] [ Next by date / thread => ]

RE: [LUG] postgresql inserts



Title: RE: [LUG] postgresql inserts

Hi,
nextval('seq_name') will never return the same number twice (even if multiple transaction call it at the same time). Of course I would still agree you'd want a unique index on a unique column still.

Cheers,
- Stuart
P.S. Sorry about the disclaimer adder changing the format :(

> -----Original Message-----
> From: Pete Hatton [mailto:pete@xxxxxxxxxxxxx]
>
> > Hi, thanks for this idea.
> > As this reqiures 2 SQL commands, I am worried that there may be some
> > problems if this procedure should be run by a different
> user inbetween
> > these commands. I would consider transaction locking,
> however sequences
> > values are not locked. Any ideas on how to secure this?
> >
> Not used Postgresql myself, but my thoughts are make to make
> the field
> that usess the sequence number a primary key or a index with
> no duplicates. 
>
> Then witb a commit and rollback it shouldn't cause any problems.
>
> eg
>
> begin transaction
> sql to get next sequence number
> insert data into table
> if insert fails due to a primary key constraint or index constraint
>   rollback
> else
>   commit
>
> Stored procedures are you friend here :)
>


DISCLAIMER:The information in this message is confidential and may be legally privileged. It is intended solely for the addressee.  Access to this message by anyone else is unauthorised.  If you are not the intended recipient, any disclosure, copying, or distribution of the message, or any action or omission taken by you in reliance on it, is prohibited and may be unlawful.  Please immediately contact the sender if you have received this message in error. Thank you.



Lynx friendly