Sample Header Ad - 728x90

Is concurrently using nextval with generate_series guaranteed to return incremental values?

2 votes
1 answer
263 views
I need to obtain multiple values from a sequence with only one query. On Stack Overflow I found this: https://stackoverflow.com/questions/896274/select-multiple-ids-from-a-postgresql-sequence The solution seems to be the following:
select nextval('my_sequence') from generate_series(1, N)
How does this behave when my application could launch this query concurrently each time it serves some client request? The top-voted answer has a comment that reads: > Note that the 3 numbres (nextvals) are not guaranteed to be sequential. I don't necessarily care about sequentiality, but is it guaranteed that the returned values are *at least* strictly monotonically increasing, even if they may be interweaved with the values generated by another concurrent query?
Asked by blackgreen (125 rep)
Nov 20, 2024, 10:13 AM
Last activity: Nov 21, 2024, 01:44 PM