postgres primary key generation and fetch
CREATE TABLE boat
(
id serial NOT NULL,
name varchar(40) NOT NULL,
built timestamp NOT NULL,
CONSTRAINT id PRIMARY KEY (id)
)
WITHOUT OIDS;
insert into boat (name,built) values ( 'bigboat', '1965-08-11' );
-- get the generated key back
select currval(pg_get_serial_sequence('boat', 'id'));
-- or better still
select lastval();
0 Comments:
Post a Comment
<< Home