D
D
des1roer2015-07-03 15:17:58
PostgreSQL
des1roer, 2015-07-03 15:17:58

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

3 answer(s)
K
krypt3r, 2015-07-03
@krypt3r

Again, these fans touch the auto-increment in the database =/

S
Sergey, 2015-07-03
Protko @Fesor

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.

V
Vladimir Boliev, 2015-07-03
@voff

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 question

Ask a Question

731 491 924 answers to any question