{"id":651,"date":"2006-07-07T01:00:00","date_gmt":"2006-07-06T16:00:00","guid":{"rendered":"https:\/\/ecoop.net\/memo\/2006-07-07-1.html"},"modified":"2006-07-07T01:00:00","modified_gmt":"2006-07-06T16:00:00","slug":"2006-07-07-1","status":"publish","type":"post","link":"https:\/\/www.ecoop.net\/memo\/archives\/2006-07-07-1.html","title":{"rendered":"\u6700\u5f8c\u306b\u633f\u5165\u3057\u305f\u30af\u30a8\u30ea\u306e ID \u3092\u53d6\u5f97\u3059\u308b"},"content":{"rendered":"<p>\nPostgreSQL 8.1 \u306b\u306a\u3063\u3066\u3001<br \/>\nMySQL \u306b\u304a\u3051\u308b LAST_INSERT_ID() \u306b\u4f3c\u305f\u6a5f\u80fd\u3092\u3082\u3064\u3001LastVal() \u304c\u30b5\u30dd\u30fc\u30c8\u3055\u308c\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002\n<\/p>\n<blockquote><p>MySQL:<br \/>\nCREATE TABLE employee (<br \/>\n&nbsp;&nbsp;id int unsigned auto_increment not null primary key,<br \/>\n&nbsp;&nbsp;name varchar(128) not null<br \/>\n);<br \/>\n&nbsp;<br \/>\nINSERT INTO employee (name) VALUES (&#8216;John&#8217;);<br \/>\nSELECT LAST_INSERT_ID();\n<\/p><\/blockquote>\n<p>\u3068\u3001\u6b21\u306e\u3082\u306e\u306f\u5168\u304f\u540c\u7b49\u306e\u610f\u5473\u306b\u306a\u308a\u307e\u3059\u3002\n<\/p>\n<blockquote><p>PostgreSQL:<br \/>\nCREATE TABLE employee (<br \/>\n&nbsp;&nbsp;id serial not null primary key, <br \/>\n&nbsp;&nbsp;name varchar(128) not null<br \/>\n); <br \/>\n&nbsp;<br \/>\nINSERT INTO employee (name) VALUES (&#8216;John&#8217;);<br \/>\nSELECT LASTVAL();\n<\/p><\/blockquote>\n<p>&nbsp;<br \/>\nLASTVAL() \u306f\u30b7\u30fc\u30b1\u30f3\u30b9\u306e\u30a4\u30f3\u30af\u30ea\u30e1\u30f3\u30c8\u95a2\u6570\u3067\u3042\u308b NEXTVAL() \u304c\u4e00\u756a\u6700\u5f8c\u306b\u8fd4\u3057\u305f\u5024\u3092\u8fd4\u3059\u3082\u306e\u3067\u3059\u3002<br \/>\n&nbsp;<br \/>\nPostgreSQL \u306e LASTVAL() \u306f MySQL \u306e LAST_INSERT_ID() \u3068\u540c\u69d8\u306b\u3001<br \/>\n\u4ed6\u306e\u30bb\u30c3\u30b7\u30e7\u30f3\u3067\u306e NEXTVAL()\u306e\u5f71\u97ff\u306f\u53d7\u3051\u307e\u305b\u3093\u3002<br \/>\n&nbsp;<br \/>\n\u4e00\u5ea6\u3082\u81ea\u5206\u306e\u30bb\u30c3\u30b7\u30e7\u30f3\u3067 NEXTVAL() \u3092\u547c\u3073\u51fa\u3057\u3066\u3044\u306a\u3044\u5834\u5408\u306f\u3001&#8221;ERROR:  lastval is not yet defined in this session&#8221;\u3068\u3044\u3046\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u307e\u3059\u3002<br \/>\n&nbsp;<br \/>\n\u53c2\u8003:<br \/>\n<a href=\"http:\/\/opentechpress.jp\/desktop\/05\/12\/20\/0156237.shtml\">PostgreSQL \u3092 MySQL \u4e92\u63db\u306b\u3059\u308b<\/a>(Open Tech Press)<br \/>\n<a href=\"http:\/\/www.postgresql.jp\/document\/pg810doc\/html\/functions-sequence.html\">\u30b7\u30fc\u30b1\u30f3\u30b9\u64cd\u4f5c\u95a2\u6570<\/a>(PostgreSQL 8.1.0 \u65e5\u672c\u8a9e\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PostgreSQL 8.1 \u306b\u306a\u3063\u3066\u3001 MySQL \u306b\u304a\u3051\u308b LAST_INSERT_ID() \u306b\u4f3c\u305f\u6a5f\u80fd\u3092\u3082\u3064\u3001LastVal() \u304c\u30b5\u30dd\u30fc\u30c8\u3055\u308c\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002 MySQL: CREATE TABLE empl &hellip; <a href=\"https:\/\/www.ecoop.net\/memo\/archives\/2006-07-07-1.html\" class=\"more-link\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"screen-reader-text\">\u6700\u5f8c\u306b\u633f\u5165\u3057\u305f\u30af\u30a8\u30ea\u306e ID \u3092\u53d6\u5f97\u3059\u308b<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[26,45],"class_list":["post-651","post","type-post","status-publish","format-standard","hentry","tag-mysql","tag-postgresql"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/posts\/651","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/comments?post=651"}],"version-history":[{"count":0,"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/posts\/651\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/media?parent=651"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/categories?post=651"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/tags?post=651"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}