2012-08-28 82 views
0

插入可以說我有一個表temp123作爲PostgreSQL的:將選擇與返回的ID

Column  |  Type   |  Modifiers 
------------+-------------------+------------------------ 
id   | integer   | not null default nextval('temp12_id_seq'::regclass) 
description | character varying | 

我想返回的ID通過

INSERT INTO temp123 (description) 
     VALUES ('TESTING') RETURNING ID; 

以`選擇」結合起來。例如(不工作):

SELECT 23, x.* 
FROM (INSERT INTO temp123 (description) 
     VALUES ('TESTING') RETURNING id) AS x; 

不需要在你的榜樣的PostgreSQL v9.0.2

回答

4

SELECT部分​​。使用任何支持INSERT ... RETURNING(> = 8.2)的PG版本可以獲得期望的結果:

insert into temp123(description) values('TESTING') returning 23,*;