I have a table with [primary key counters] for [per page comments in another table].
These primary keys are per page: for each page, comment IDs start on 1.
I'd like to atomically allocate 10 IDs to write 10 new comments.
— Can I do this with PostgreSQL and JDBC?
(And do you have any links to any example / the relevant JDBC documentation?)
I've found only examples about how returning
the primary key of a newly inserted row, using some getGeneratedKeys
which doesn't seem useful in my case.
***
I think the SQL UPDATE statement would look something like this:
update PAGES
set NEXT_COMMENT_ID = NEXT_COMMENT_ID + 10
where PAGE_ID = ? <-- next-comment-id is *per page*
returning NEXT_COMMENT_ID into ?
So, different threads and servers won't attempt to reuse/overwrite the same IDs (right?).