0

I am trying to retrieve the ID value of an inserted row using node.js' pg module. The query is:

INSERT INTO "MySchema"."USER_ACCOUNT"
  ("LANG","NAME","EMAIL","EMAIL_CONF","STATUS","STATUS_UPDATE","CREATION","PREFERENCES")
  VALUES ($1,$2,$3,$4,$5,$6,$7,$8)
  RETURNING USER_ACCOUNT_ID_seq;

But I get the following error message:

Cannot insert user account { [error: column "user_account_id_seq" does not exist]...

I don't provide an id, because I am letting the database set the next sequence value.

How can I retrieve this ID value after the insert? Thanks!

Community
  • 1
  • 1
Jérôme Verstrynge
  • 57,710
  • 92
  • 283
  • 453
  • Although the ID is generated by the sequence, you could retrieve it from the linked column, probably called "ID" in this case, e.g. `... RETURNING "ID";` – Milen A. Radev Feb 06 '14 at 13:29
  • Arrrrrrgh, I am gonna kick myself baaad. I had tried with ID, without the "" and it did not work. A simple syntax error... If you create the solution I'll approve it! – Jérôme Verstrynge Feb 06 '14 at 13:36

1 Answers1

1

Although the ID is generated by the sequence, you could retrieve it from the linked column, probably called "ID" in this case, e.g. ... RETURNING "ID";.

"How do I get the value of a SERIAL insert?"

Milen A. Radev
  • 60,241
  • 22
  • 105
  • 110