serial

SQLite: How to get the “autoincrement” value from the last insert

SQLite autoincrement FAQ: How do I get the autoincrement value from my last SQLite INSERT command?

You can get the integer value of the primary key field from the last insert into an autoincrement field using a SQLite function named last_insert_rowid(), as shown in the example below.

How to get the Postgresql serial field value after an INSERT

Assuming you are using Postgres (Postgresql), and:

  • you have *just* done an INSERT into a table named order,
  • the name of the sequence for that table is order_order_id_seq
  • you are using the Java programming language
  • you are still using the same database connection that you used with your INSERT statement

to get the value of the Postgres serial value just created after your INSERT statement, use some code like this: