Terumi's avatar

Postgres does not return last_insert_id

Hello, I have an app which uses postgres. I developed it usign sqlite and when I made the switch to posgress, after trying to create a new user I got this error

Syntax error: 7 ERROR: syntax error at or near "returning" at character 107 
(SQL: insert into "users" ("name", "email", "password", "updated_at", "created_at") values (Example, support@domain.gr, some_rand_str, 2015-02-16 13:28:46, 2015-02-16 13:28:46) returning "id") 

I had the same problem with another application using pgsql as well, but I cannot remember how I rackled it. Can anyone help please?

Thank you

0 likes
9 replies
pmall's avatar

I use postgres and everything works fine. Can you show some code ?

Terumi's avatar

It is the default auth controller code!

pmall's avatar

I guess something is wrong with your pgsql setup because everything works fine.

You didn't modified anything in the code ?

Terumi's avatar

nope, it is the plain auth controller code.

pmall's avatar

Did you create the table with the default migrations ?

Terumi's avatar

yep, I think that it has to do something with the version of postgres in my machine. I currently running 8.1.23 which, I don't know if supports "returning".

:(

Terumi's avatar

Nope, it is a production server. I'm running postgres for sure, I created the migrations and on my postgres client saw the tables being created.

murilo's avatar

try to run this code in postgres -

SELECT setval('table_name_id_seq'::regclass, MAX(id)) FROM table_name;

Please or to participate in this conversation.