0

I'm re-developing an open-source program developed with MySql and re-writing an method like:

function lastid(){
    return mysql_insert_id($conn);
}

How can i perform this function using postgresql instead?

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
藍劍樟
  • 41
  • 8

1 Answers1

0

According to the manual: http://www.postgresql.org/docs/current/static/functions-sequence.html there is a function lastval() that

Return the value most recently returned by nextval in the current session. This function is identical to currval, except that instead of taking the sequence name as an argument it fetches the value of the last sequence that nextval was used on in the current session. It is an error to call lastval if nextval has not yet been called in the current session.

Ihor Romanchenko
  • 26,995
  • 8
  • 48
  • 44