{"id":1645,"date":"2024-05-08T17:18:02","date_gmt":"2024-05-08T09:18:02","guid":{"rendered":"http:\/\/oneai.eu.org\/?p=1645"},"modified":"2024-05-08T17:18:02","modified_gmt":"2024-05-08T09:18:02","slug":"%e5%ba%8f%e5%88%97%e5%88%9b%e5%bb%ba%e4%b8%8e%e5%bc%95%e7%94%a8","status":"publish","type":"post","link":"https:\/\/oneai.eu.org\/?p=1645","title":{"rendered":"\u5e8f\u5217\u521b\u5efa\u4e0e\u5f15\u7528"},"content":{"rendered":"<p>CREATE SEQUENCE test_sequence2<br \/>\nincrement by 1    -- \u6bcf\u6b21\u9012\u589e1<br \/>\nstart with 1       -- \u4ece1\u5f00\u59cb<br \/>\nNO MAXVALUE       -- \u6ca1\u6709\u6700\u5927\u503c<br \/>\nminvalue 1       -- \u6700\u5c0f\u503c=1<br \/>\nNO CYCLE;      -- \u4e0d\u5faa\u73af<\/p>\n<p>\u8bed\u6cd5\uff1a<br \/>\nCREATE [ TEMPORARY | TEMP ] SEQUENCE name [ INCREMENT [ BY ] increment ]<br \/>\n[ MINVALUE minvalue | NO MINVALUE ] [ MAXVALUE maxvalue | NO MAXVALUE ]<br \/>\n[ START [ WITH ] start ] [ CACHE cache ] [ [ NO ] CYCLE ]<br \/>\nCREATE SEQUENCE test_sequence2<br \/>\nincrement by 1    -- \u6bcf\u6b21\u9012\u589e1<br \/>\nstart with 1       -- \u4ece1\u5f00\u59cb<br \/>\nNO MAXVALUE       -- \u6ca1\u6709\u6700\u5927\u503c<br \/>\nminvalue 1       -- \u6700\u5c0f\u503c=1<br \/>\nNO CYCLE;      -- \u4e0d\u5faa\u73af<\/p>\n<h2>-- \u4e0b\u4e00\u4e2a\u5e8f\u5217\u53f7<br \/>\nTest=# SELECT nextval ('test_sequence2');<br \/>\nnextval<\/h2>\n<pre><code>   1<\/code><\/pre>\n<p>(1 \u884c\u8bb0\u5f55)<\/p>\n<h2>-- \u4e0b\u4e00\u4e2a\u5e8f\u5217\u53f7<br \/>\nTest=# SELECT nextval ('test_sequence2');<br \/>\nnextval<\/h2>\n<pre><code>   2<\/code><\/pre>\n<p>(1 \u884c\u8bb0\u5f55)<\/p>\n<h2>-- \u5f53\u524d\u5e8f\u5217\u53f7<br \/>\nTest=# SELECT CURRVAL ('test_sequence2');<br \/>\ncurrval<\/h2>\n<pre><code>   2<\/code><\/pre>\n<p>(1 \u884c\u8bb0\u5f55)<\/p>\n<p>\u53ef\u7528\u7684\u5e8f\u5217\u51fd\u6570\u6709\u2236<br \/>\nnextval<br \/>\n\u9012\u589e\u5e8f\u5217\u5bf9\u8c61\u5230\u5b83\u7684\u4e0b\u4e00\u4e2a\u6570\u503c\u5e76\u4e14\u8fd4\u56de\u8be5\u503c\u3002\u8fd9\u4e2a\u52a8\u4f5c\u662f\u81ea\u52a8\u5b8c\u6210\u7684\uff1a<br \/>\n\u5373\u4f7f\u591a\u4e2a\u4f1a\u8bdd\u5e76\u53d1\u8fd0\u884c nextval\uff0c\u6bcf\u4e2a\u8fdb\u7a0b\u4e5f\u4f1a\u5b89\u5168\u5730\u6536\u5230\u4e00\u4e2a\u552f\u4e00\u7684\u5e8f\u5217\u503c\u3002<\/p>\n<p>currval<br \/>\n\u5728\u5f53\u524d\u4f1a\u8bdd\u4e2d\u8fd4\u56de\u6700\u8fd1\u4e00\u6b21 nextval \u6293\u5230\u7684\u8be5\u5e8f\u5217\u7684\u6570\u503c\u3002<br \/>\n\uff08\u5982\u679c\u5728\u672c\u4f1a\u8bdd\u4e2d\u4ece\u672a\u5728\u8be5\u5e8f\u5217\u4e0a\u8c03\u7528\u8fc7 nextval\uff0c \u90a3\u4e48\u4f1a\u62a5\u544a\u4e00\u4e2a\u9519\u8bef\u3002\uff09\u8bf7\u6ce8\u610f\u56e0\u4e3a\u6b64\u51fd\u6570\u8fd4\u56de\u4e00\u4e2a\u4f1a\u8bdd\u8303\u56f4\u7684\u6570\u503c\uff0c \u5b83\u4e5f\u80fd\u7ed9\u51fa\u4e00\u4e2a\u53ef\u9884\u8ba1\u7684\u7ed3\u679c\uff0c\u53ef\u4ee5\u5224\u65ad\u5176\u5b83\u4f1a\u8bdd\u662f\u5426\u6267\u884c\u8fc7 nextval\u3002<\/p>\n<p>lastval<br \/>\n\u8fd4\u56de\u5f53\u524d\u4f1a\u8bdd\u91cc\u6700\u8fd1\u4e00\u6b21 nextval \u8fd4\u56de\u7684\u6570\u503c\u3002<br \/>\n\u8fd9\u4e2a\u51fd\u6570\u7b49\u6548\u4e8e currval\uff0c\u53ea\u662f\u5b83\u4e0d\u7528\u5e8f\u5217\u540d\u4f4d\u53c2\u6570\uff0c \u5b83\u6293\u53d6\u5f53\u524d\u4f1a\u8bdd\u91cc\u9762\u6700\u8fd1\u4e00\u6b21 nextval \u4f7f\u7528\u7684\u5e8f\u5217\u3002<br \/>\n\u5982\u679c\u5f53\u524d\u4f1a\u8bdd\u8fd8\u6ca1\u6709\u8c03\u7528\u8fc7 nextval\uff0c\u90a3\u4e48\u8c03\u7528 lastval \u662f\u4f1a\u62a5\u9519\u7684\u3002<\/p>\n<p>setval<br \/>\n\u91cd\u7f6e\u5e8f\u5217\u5bf9\u8c61\u7684\u8ba1\u6570\u5668\u6570\u503c\u3002<br \/>\n\u53cc\u53c2\u6570\u7684\u5f62\u5f0f\u8bbe\u7f6e\u5e8f\u5217\u7684 last_value \u5b57\u6bb5\u4e3a\u58f0\u660e\u6570\u503c\u5e76\u4e14\u5c06\u5176 is_called \u5b57\u6bb5\u8bbe\u7f6e\u4e3a true\uff0c<br \/>\n\u8868\u793a\u4e0b\u4e00\u6b21 nextval \u5c06\u5728\u8fd4\u56de\u6570\u503c\u4e4b\u524d\u9012\u589e\u8be5\u5e8f\u5217\u3002<br \/>\n\u5728\u4e09\u53c2\u6570\u5f62\u5f0f\u91cc\uff0cis_called \u53ef\u4ee5\u8bbe\u7f6e\u4e3a true \u6216 false\u3002<br \/>\n\u5982\u679c\u4f60\u628a\u5b83\u8bbe\u7f6e\u4e3a false\uff0c\u90a3\u4e48\u4e0b\u4e00\u6b21 nextval \u5c06\u8fd4\u56de\u8fd9\u91cc\u58f0\u660e\u7684\u6570\u503c\uff0c<br \/>\n\u800c\u4ece\u968f\u540e\u7684 nextval \u624d\u5f00\u59cb\u9012\u589e\u8be5\u5e8f\u5217\u3002<br \/>\n\u6bd4\u5982<br \/>\nSELECT setval('foo', 42);    \u4e0b\u6b21nextval\u5c06\u8fd4\u56de 43<br \/>\nSELECT setval('foo', 42, true);     \u548c\u4e0a\u9762\u4e00\u6837<br \/>\nSELECT setval('foo', 42, false);    \u4e0b\u6b21nextval\u5c06\u8fd4\u56de 42<br \/>\nsetval \u8fd4\u56de\u7684\u7ed3\u679c\u5c31\u662f\u5b83\u7684\u7b2c\u4e8c\u4e2a\u53c2\u6570\u7684\u6570\u503c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>CREATE SEQUENCE test_sequence2 increment by 1 &#8212; \u6bcf\u6b21\u9012\u589e1 start with 1 &#8212; \u4ece1\u5f00\u59cb NO MAXVALUE &#8212; \u6ca1\u6709\u6700\u5927\u503c minvalue 1 &#8212; \u6700\u5c0f\u503c=1 NO CYCLE; &#8212; \u4e0d\u5faa\u73af \u8bed\u6cd5\uff1a CREATE [ TEMPORARY | TEMP ] SEQUENCE name [ INCREMENT [ BY ] increment ] [ MINVALUE minvalue | NO MINVALUE ] [ MAXVALUE maxvalue | NO MAXVALUE ] [ START [ WITH ] start ] [ CACHE cache ] [ [ NO ] CYCLE ] CREATE SEQUENCE test_sequence2 increment by 1 &#8212; \u6bcf\u6b21\u9012\u589e1 start with 1 &#8212; \u4ece1\u5f00\u59cb NO MAXVALUE &#8212; \u6ca1\u6709\u6700\u5927\u503c minvalue 1 &#8212; \u6700\u5c0f\u503c=1 NO CYCLE; &#8212; \u4e0d\u5faa\u73af &#8212; \u4e0b\u4e00\u4e2a\u5e8f\u5217\u53f7 Test=# SELECT nextval (&#8216;test_sequence2&#8217;); nextval 1 (1 \u884c\u8bb0\u5f55) &#8212; \u4e0b\u4e00\u4e2a\u5e8f\u5217\u53f7 Test=# SELECT nextval (&#8216;test_sequence2&#8217;); nextval 2 (1 \u884c\u8bb0\u5f55) &#8212; \u5f53\u524d\u5e8f\u5217\u53f7 Test=# SELECT CURRVAL (&#8216;test_sequence2&#8217;); currval 2 (1 \u884c\u8bb0\u5f55) \u53ef\u7528\u7684\u5e8f\u5217\u51fd\u6570\u6709\u2236 nextval \u9012\u589e\u5e8f\u5217\u5bf9\u8c61\u5230\u5b83\u7684\u4e0b\u4e00\u4e2a\u6570\u503c\u5e76\u4e14\u8fd4\u56de\u8be5\u503c\u3002\u8fd9\u4e2a\u52a8\u4f5c\u662f\u81ea\u52a8\u5b8c\u6210\u7684\uff1a \u5373\u4f7f\u591a\u4e2a\u4f1a\u8bdd\u5e76\u53d1\u8fd0\u884c nextval\uff0c\u6bcf\u4e2a\u8fdb\u7a0b\u4e5f\u4f1a\u5b89\u5168\u5730\u6536\u5230\u4e00\u4e2a\u552f\u4e00\u7684\u5e8f\u5217\u503c\u3002 currval \u5728\u5f53\u524d\u4f1a\u8bdd\u4e2d\u8fd4\u56de\u6700\u8fd1\u4e00\u6b21 nextval \u6293\u5230\u7684\u8be5\u5e8f\u5217\u7684\u6570\u503c\u3002 \uff08\u5982\u679c\u5728\u672c\u4f1a\u8bdd\u4e2d\u4ece\u672a\u5728\u8be5\u5e8f\u5217\u4e0a\u8c03\u7528\u8fc7 nextval\uff0c \u90a3\u4e48\u4f1a\u62a5\u544a\u4e00\u4e2a\u9519\u8bef\u3002\uff09\u8bf7\u6ce8\u610f\u56e0\u4e3a\u6b64\u51fd\u6570\u8fd4\u56de\u4e00\u4e2a\u4f1a\u8bdd\u8303\u56f4\u7684\u6570\u503c\uff0c \u5b83\u4e5f\u80fd\u7ed9\u51fa\u4e00\u4e2a\u53ef\u9884\u8ba1\u7684\u7ed3\u679c\uff0c\u53ef\u4ee5\u5224\u65ad\u5176\u5b83\u4f1a\u8bdd\u662f\u5426\u6267\u884c\u8fc7 nextval\u3002 lastval \u8fd4\u56de\u5f53\u524d\u4f1a\u8bdd\u91cc\u6700\u8fd1\u4e00\u6b21 nextval \u8fd4\u56de\u7684\u6570\u503c\u3002 \u8fd9\u4e2a\u51fd\u6570\u7b49\u6548\u4e8e currval\uff0c\u53ea\u662f\u5b83\u4e0d\u7528\u5e8f\u5217\u540d\u4f4d\u53c2\u6570\uff0c \u5b83\u6293\u53d6\u5f53\u524d\u4f1a\u8bdd\u91cc\u9762\u6700\u8fd1\u4e00\u6b21 nextval \u4f7f\u7528\u7684\u5e8f\u5217\u3002 \u5982\u679c\u5f53\u524d\u4f1a\u8bdd\u8fd8\u6ca1\u6709\u8c03\u7528\u8fc7 nextval\uff0c\u90a3\u4e48\u8c03\u7528 lastval \u662f\u4f1a\u62a5\u9519\u7684\u3002 setval \u91cd\u7f6e\u5e8f\u5217\u5bf9\u8c61\u7684\u8ba1\u6570\u5668\u6570\u503c\u3002 \u53cc\u53c2\u6570\u7684\u5f62\u5f0f\u8bbe\u7f6e\u5e8f\u5217\u7684 last_value \u5b57\u6bb5\u4e3a\u58f0\u660e\u6570\u503c\u5e76\u4e14\u5c06\u5176 is_called \u5b57\u6bb5\u8bbe\u7f6e\u4e3a true\uff0c \u8868\u793a\u4e0b\u4e00\u6b21 nextval \u5c06\u5728\u8fd4\u56de\u6570\u503c\u4e4b\u524d\u9012\u589e\u8be5\u5e8f\u5217\u3002 \u5728\u4e09\u53c2\u6570\u5f62\u5f0f\u91cc\uff0cis_called \u53ef\u4ee5\u8bbe\u7f6e\u4e3a true \u6216 false\u3002 \u5982\u679c\u4f60\u628a\u5b83\u8bbe\u7f6e\u4e3a false\uff0c\u90a3\u4e48\u4e0b\u4e00\u6b21 nextval \u5c06\u8fd4\u56de\u8fd9\u91cc\u58f0\u660e\u7684\u6570\u503c\uff0c \u800c\u4ece\u968f\u540e\u7684 nextval \u624d\u5f00\u59cb\u9012\u589e\u8be5\u5e8f\u5217\u3002 \u6bd4\u5982 SELECT setval(&#8216;foo&#8217;, 42); \u4e0b\u6b21nextval\u5c06\u8fd4\u56de 43 SELECT setval(&#8216;foo&#8217;, 42, true); \u548c\u4e0a\u9762\u4e00\u6837 SELECT setval(&#8216;foo&#8217;, 42, false); \u4e0b\u6b21nextval\u5c06\u8fd4\u56de 42 setval \u8fd4\u56de\u7684\u7ed3\u679c\u5c31\u662f\u5b83\u7684\u7b2c\u4e8c\u4e2a\u53c2\u6570\u7684\u6570\u503c\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_eb_attr":"","footnotes":""},"categories":[89],"tags":[],"class_list":["post-1645","post","type-post","status-publish","format-standard","hentry","category-postgres-db"],"_links":{"self":[{"href":"https:\/\/oneai.eu.org\/index.php?rest_route=\/wp\/v2\/posts\/1645","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/oneai.eu.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/oneai.eu.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/oneai.eu.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/oneai.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1645"}],"version-history":[{"count":1,"href":"https:\/\/oneai.eu.org\/index.php?rest_route=\/wp\/v2\/posts\/1645\/revisions"}],"predecessor-version":[{"id":1646,"href":"https:\/\/oneai.eu.org\/index.php?rest_route=\/wp\/v2\/posts\/1645\/revisions\/1646"}],"wp:attachment":[{"href":"https:\/\/oneai.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1645"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/oneai.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1645"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/oneai.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1645"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}