Hi
I have a table that is set to auto increment for the PK. Is there a command I can use so that I can get the generated auto increment key right after I insert?
Thanks!
getting back id generated via autoincrement
Moderator: NorbertKrupa
- JimKnicely
- Site Admin
- Posts: 1825
- Joined: Sat Jan 21, 2012 4:58 am
- Contact:
Re: getting back id generated via autoincrement
Check out the LAST_INSERT_ID function!
https://my.vertica.com/docs/7.2.x/HTML/ ... ERT_ID.htm
Example:
https://my.vertica.com/docs/7.2.x/HTML/ ... ERT_ID.htm
Example:
Code: Select all
dbadmin=> create table earth (wind auto_increment, fire varchar(20));
CREATE TABLE
dbadmin=> insert into earth (fire) values ('Disco Lives!');
OUTPUT
--------
1
(1 row)
dbadmin=> select * from earth;
wind | fire
------+--------------
1 | Disco Lives!
(1 row)
dbadmin=> select last_insert_id();
last_insert_id
----------------
1
(1 row)
Jim Knicely
Note: I work for Vertica. My views, opinions, and thoughts expressed here do not represent those of my employer.
Note: I work for Vertica. My views, opinions, and thoughts expressed here do not represent those of my employer.