PostgreSQL - next serial value in a table

后端 未结 3 487
鱼传尺愫
鱼传尺愫 2021-01-03 19:09

I have a simple question, suppose we have a table:

 id   A   B
 1   Jon  Doe
 2   Foo  Bar

Is there a way to know, which is the next id\'s

3条回答
  •  执笔经年
    2021-01-03 19:33

    SELECT currval('names_id_seq') + 1;

    See the docs

    However, of course, there's no guarantee that it's going to be your next value. What if another client grabs it before you? You can though reserve one of the next values for yourself, selecting a nextval from the sequence.

提交回复
热议问题