Created
October 31, 2014 09:19
-
-
Save s4553711/9afe5bcbc3902a663232 to your computer and use it in GitHub Desktop.
使用Sequence的值作為及將要新增欄位的值
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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