{"id":1030,"date":"2023-12-28T21:46:25","date_gmt":"2023-12-28T12:46:25","guid":{"rendered":"https:\/\/shinke1987.net\/?p=1030"},"modified":"2023-12-28T21:46:25","modified_gmt":"2023-12-28T12:46:25","slug":"postgresql%e3%81%ae%e3%82%b7%e3%83%bc%e3%82%b1%e3%83%b3%e3%82%b9%e3%81%ae%e5%8b%95%e4%bd%9c%e7%a2%ba%e8%aa%8d","status":"publish","type":"post","link":"https:\/\/shinke1987.net\/?p=1030","title":{"rendered":"PostgreSQL\u306e\u30b7\u30fc\u30b1\u30f3\u30b9\u306e\u52d5\u4f5c\u78ba\u8a8d"},"content":{"rendered":"\n<h2 id=\"toc0\" class=\"wp-block-heading\">\u30b7\u30fc\u30b1\u30f3\u30b9\u306e\u73fe\u5728\u5024\u3092\u78ba\u8a8d<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nSELECT last_value FROM \u30b7\u30fc\u30b1\u30f3\u30b9\u540d;\n<\/pre><\/div>\n\n\n<h2 id=\"toc1\" class=\"wp-block-heading\">100\u523b\u307f\u306e\u30b7\u30fc\u30b1\u30f3\u30b9\u3092\u4f5c\u6210\u3057\u3001\u9069\u7528<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\n-- \u30c6\u30b9\u30c8\u7528\u30c6\u30fc\u30d6\u30eb\u4f5c\u6210\nCREATE TABLE sequence_test (\n    id smallint,\n    temp varchar(100)\n);\n\n-- \u30b7\u30fc\u30b1\u30f3\u30b9\u4f5c\u6210\nCREATE SEQUENCE test_100sequence INCREMENT 100 START 100 CYCLE;\n\n-- \u30b7\u30fc\u30b1\u30f3\u30b9\u3092\u5229\u7528\u3057\u3066\u30c7\u30fc\u30bf\u633f\u5165\nINSERT INTO sequence_test VALUES (nextval(&#039;test_100sequence&#039;), &#039;aiueo&#039;);\nINSERT INTO sequence_test VALUES (nextval(&#039;test_100sequence&#039;), &#039;kakikukeko&#039;);\n\n-- CREATE SEQUENCE\u3067\u4f5c\u6210\u3057\u305f\u30b7\u30fc\u30b1\u30f3\u30b9\u3092\u30c6\u30fc\u30d6\u30eb\u306b\u7d10\u4ed8\u3051\u308b\u624b\u9806\u306f\u672a\u78ba\u8a8d\u3002\n<\/pre><\/div>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\n-- \u30c6\u30b9\u30c8\u7528\u30c6\u30fc\u30d6\u30eb\u4f5c\u6210\nCREATE TABLE sequence_test (\n    id smallint,\n    temp varchar(100)\n);\n\n-- \u30b7\u30fc\u30b1\u30f3\u30b9\u3092\u7d10\u4ed8\u3051\u308b\u5217\u306fNOT NULL\u5236\u7d04\u304c\u5fc5\u8981\u3002\nALTER TABLE sequence_test ALTER COLUMN id SET NOT NULL;\n\n-- NOT NULL\u5236\u7d04\u3092\u78ba\u8a8d\u3002\nSELECT table_name, constraint_type, constraint_name\nFROM information_schema.table_constraints\nWHERE table_schema = &#039;public&#039;\nAND table_name = &#039;sequence_test&#039;;\n\n-- \u30b7\u30fc\u30b1\u30f3\u30b9\u3092\u8ffd\u52a0\nALTER TABLE sequence_test\n    ALTER COLUMN id ADD GENERATED BY DEFAULT AS IDENTITY (INCREMENT 100 START 100 CYCLE);\n\n-- \u30c7\u30fc\u30bf\u633f\u5165\nINSERT INTO sequence_test(temp) VALUES (&#039;aiueo&#039;);\nINSERT INTO sequence_test(temp) VALUES (&#039;kakikukeko&#039;);\nINSERT INTO sequence_test VALUES (101, &#039;sashisuseso&#039;);\n\n\u203b \u4e0a\u8a18\u624b\u9806\u3067\u30b7\u30fc\u30b1\u30f3\u30b9\u304c\u4f5c\u6210\u3055\u308c\u3001\u5217\u306b\u7d10\u4ed8\u3051\u3089\u308c\u308b\u304c\u3001\n\u60c5\u5831\u30b9\u30ad\u30fc\u30de\u3092\u5229\u7528\u3057\u3066\u30b7\u30fc\u30b1\u30f3\u30b9\u306e\u78ba\u8a8d\u304c\u3067\u304d\u306a\u304b\u3063\u305f\u3002\npsql\u30b3\u30de\u30f3\u30c9\u3067\\d+\u30e1\u30bf\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3059\u308b\u3068\u3001\u30b7\u30fc\u30b1\u30f3\u30b9\u306e\u78ba\u8a8d\u306f\u3067\u304d\u305f\u3002\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>\u30b7\u30fc\u30b1\u30f3\u30b9\u306e\u73fe\u5728\u5024\u3092\u78ba\u8a8d 100\u523b\u307f\u306e\u30b7\u30fc\u30b1\u30f3\u30b9\u3092\u4f5c\u6210\u3057\u3001\u9069\u7528<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[56],"tags":[57],"class_list":["post-1030","post","type-post","status-publish","format-standard","hentry","category-postgresql","tag-postgresql"],"_links":{"self":[{"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/posts\/1030","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/shinke1987.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1030"}],"version-history":[{"count":1,"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/posts\/1030\/revisions"}],"predecessor-version":[{"id":1031,"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/posts\/1030\/revisions\/1031"}],"wp:attachment":[{"href":"https:\/\/shinke1987.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1030"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/shinke1987.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1030"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/shinke1987.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1030"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}