mysql_insert_id alternative for postgresql

后端 未结 4 526
借酒劲吻你
借酒劲吻你 2020-12-01 15:53

is there an alternative for mysql_insert_id() php function for PostgreSQL? Most of the frameworks are solving the problem partially by finding the current value

4条回答
  •  Happy的楠姐
    2020-12-01 16:48

    Check out the RETURNING optional clause for an INSERT statement. (Link to official PostgreSQL documentation)

    But basically, you do:

    INSERT INTO table (col1, col2) VALUES (1, 2) RETURNING pkey_col
    

    and the INSERT statement itself returns the id (or whatever expression you specify) of the affected row.

提交回复
热议问题