PostgreSQL function for last inserted ID

后端 未结 11 1369

In PostgreSQL, how do I get the last id inserted into a table?

In MS SQL there is SCOPE_IDENTITY().

Please do not advise me to use something like this:

11条回答
  •  一向
    一向 (楼主)
    2020-11-22 14:31

    SELECT CURRVAL(pg_get_serial_sequence('my_tbl_name','id_col_name'))
    

    You need to supply the table name and column name of course.

    This will be for the current session / connection http://www.postgresql.org/docs/8.3/static/functions-sequence.html

提交回复
热议问题