Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix last insert ID not being returned with postgresql. #62

Closed
wants to merge 1 commit into from
Closed

Fix last insert ID not being returned with postgresql. #62

wants to merge 1 commit into from

Conversation

laacz
Copy link
Contributor

@laacz laacz commented Jul 4, 2012

When using PostgreSQL, upon saving new entries id is not being updated.

That's because PDO's implementation of lastInsertId requires sequence name as a parameter. One of three available options is fetching LASTVAL(). All three are described in the answer to this SO question.

I 'fixed' it by adding driver specific last_insert_id() method to ORM class.

@treffynnon
Copy link
Collaborator

I am thinking that RETURNING id is possibly the better of all the options there for this. I don't regularly use Postgres though so can anyone else chime in?

@treffynnon
Copy link
Collaborator

This feature is going to slip to version 1.4 as there has been no further input.

@laacz
Copy link
Contributor Author

laacz commented Dec 19, 2012

Thank you. I missed this notification from github. Answering your question - RETURNING would be an option, but this feature is present only since Postgres 9.1.

@treffynnon
Copy link
Collaborator

Is it likely that the servers will not have been upgraded to version 9.1? Ubuntu appear to have been running 9.1 as the default postgresql package for over a year now (Oneiric) although Debian are still 8.4 from what I can see.

@laacz
Copy link
Contributor Author

laacz commented Dec 19, 2012

I would bet that there is still a lot of 8.x servers out there. Some are just legacy systems, others probably do not upgrade for various reasons (plugin compatibility, syntax changes, no need to, etc). I would not rely on 9.1 being the minimum version available.

@treffynnon
Copy link
Collaborator

According to comments in the answer on the SO question that you linked to the RETURNING method works in 8.2.

In fact as I go back through documentation RETURNING appears to exists right back to version 8.2 of PostgreSQL.

@laacz
Copy link
Contributor Author

laacz commented Dec 19, 2012

@treffynnon Oh, then I read it diagonally. Relied on best answer. Then, of course, RETURNING is the way to go and falling back to SELECT from sequence only on older versions.

@treffynnon
Copy link
Collaborator

Is there anyway you could have a go at getting RETURNING to work as a pull request instead of LASTVAL()?

@laacz
Copy link
Contributor Author

laacz commented Dec 19, 2012

OK, I'll do that. That will be separate pull request then.

@treffynnon
Copy link
Collaborator

That would be perfect. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants