postgresql不支持last_insert_id()方法,噁心到啦;sql
不過還好它有其餘的解決方案:post
建立一個測試數據表:測試
CREATE TABLE test.test18 ( id serial NOT NULL, ddd character varying )
1、先過去不重複的主鍵id,而後再插入spa
獲取他的Sequence,select nextval('test.test18_id_seq'),而後再插入便可!postgresql
2、返回主鍵idcode
insert into test.test18 (ddd) values ('3') RETURNING id;blog