Skip to content

Instantly share code, notes, and snippets.

@s4553711
Created October 31, 2014 09:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save s4553711/9afe5bcbc3902a663232 to your computer and use it in GitHub Desktop.
Save s4553711/9afe5bcbc3902a663232 to your computer and use it in GitHub Desktop.
使用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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment