I are currently using nextval() function for postgresql insert id ,But now i want to implement this function in python to generate the id which will later inserted into the postgresql. Any idea what's the Pseudocode of this function, or in python. Thanks in Advance
Look at nextval_internal
in src/backend/commands/sequence.c
.
Essentially, you lock the object against concurrent access, then increment or decrement according to the sequence definitions, unlock the object and return the new value.
The hard part is to persist this modification efficiently, so that you can be sure that you don't deal out duplicate values if the application happens to crash.
Databases are particularly good at persisting this efficiently and reliably, so you are best off using database sequences rather than trying to re-invent the wheel.