Answer the question
In order to leave comments, you need to log in
Postgres getting guessed id?
how to get the id of the next post? field type serial, respectively autoincrement
Answer the question
In order to leave comments, you need to log in
serial is nothing more than a combination of sequence and automatic execution of nextval on insertion.
The most convenient (in my opinion) option is to pull nextval manually before inserting and set the ID explicitly.
But in general, you can get the last value generated by the sequence, just do it after each request.
I know that this answer will not suit you, but if you need to know the record id before inserting, you have some problems with the architecture somewhere. Perhaps you are looking at the problem from the wrong angle. Well, at least, predicting id is an extremely dangerous undertaking, even if right now you don’t think so.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question