currval has not yet been defined this session, how to get multi-session sequences?

前端 未结 5 1137
再見小時候
再見小時候 2020-12-25 11:38

My objective is to get a primary key field automatically inserted when inserting new row in the table.

How to get a sequence going from session to session in Postg

5条回答
  •  天命终不由人
    2020-12-25 12:01

    Actually nextval will advance sequence and return the new value, so that would be the answer for your question.

    currval will return the value most recently obtained with nextval for specified sequence (This though might fail if there wasn't nextval used in current session).

提交回复
热议问题