Hi,

I've got a table where I want to group related rows with a unique id. I 
could use something like:

next_val = db.table.unique_id.max() + 1

But that does not seem safe against updates happening at almost the same 
time (I might be being paranoid). I could also use:

next_val = uuid.uuid4

But that seems like overkill - and an ugly thing to pass as a variable to a 
URL. So, the most obvious solution is to use a DB sequence (I'm using 
postgres, if it matters). That way I can grab the next value from the 
sequence, be sure I'm always getting a unique value and I've got simple 
integers. I can always create the sequence manually on the backend and then 
use:

next_val = db.executesql("select nextval('unique_id_seq');")

But is there an elegant way to do this within pydal? It would be nice to 
define the sequence in the model in the same way that tables are defined.

Thanks,
David

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to