s4553711
10/31/2014 - 9:19 AM

使用Sequence的值作為及將要新增欄位的值

使用Sequence的值作為及將要新增欄位的值

-- Show current sequence val
select currval('nodefolder_id_seq'::regclass);

-- Let insert the data with currval as value
BEGIN; 
insert into node (name,parent,type, project_id) 
	values ('TEST_Name',null,1,currval('nodefolder_id_seq'::regclass)); 
COMMIT;

-- Reference
-- 1. http://www.postgresql.org/docs/9.1/static/transaction-iso.html
-- 2. http://www.postgresql.org/docs/9.1/static/functions-sequence.html
-- 3. http://stackoverflow.com/questions/241003/how-to-get-a-value-from-the-last-inserted-row