{"id":5019,"date":"2024-05-23T13:48:14","date_gmt":"2024-05-23T04:48:14","guid":{"rendered":"https:\/\/blog.since2020.jp\/?p=5019"},"modified":"2024-05-23T13:49:33","modified_gmt":"2024-05-23T04:49:33","slug":"amazon-redshift-table","status":"publish","type":"post","link":"https:\/\/since2020.jp\/media\/amazon-redshift-table\/","title":{"rendered":"Amazon Redshift\u3067\u306e\u30b9\u30ad\u30fc\u30de\u79fb\u884c\u306e\u52b9\u7387\u7684\u306a\u65b9\u6cd5"},"content":{"rendered":"\n<p>Amazon Redshift\u306f\u3001\u9ad8\u6027\u80fd\u306a\u30c7\u30fc\u30bf\u30a6\u30a7\u30a2\u30cf\u30a6\u30b9\u30bd\u30ea\u30e5\u30fc\u30b7\u30e7\u30f3\u3068\u3057\u3066\u3001\u591a\u304f\u306e\u4f01\u696d\u3067\u63a1\u7528\u3055\u308c\u3066\u3044\u307e\u3059\u3002\u3057\u304b\u3057\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u904b\u7528\u4e2d\u306b\u30b9\u30ad\u30fc\u30de\u306e\u518d\u7de8\u6210\u304c\u5fc5\u8981\u306b\u306a\u308b\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002\u4f8b\u3048\u3070\u3001\u65b0\u3057\u3044\u30c7\u30fc\u30bf\u30e2\u30c7\u30eb\u306b\u79fb\u884c\u3059\u308b\u969b\u3084\u3001\u65e2\u5b58\u306e\u30c7\u30fc\u30bf\u69cb\u9020\u3092\u6700\u9069\u5316\u3059\u308b\u305f\u3081\u306b\u3001\u30c6\u30fc\u30d6\u30eb\u3092\u5225\u306e\u30b9\u30ad\u30fc\u30de\u306b\u79fb\u52d5\u3059\u308b\u3053\u3068\u304c\u6c42\u3081\u3089\u308c\u308b\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002\u3053\u306e\u8a18\u4e8b\u3067\u306f\u3001Amazon Redshift\u306b\u304a\u3044\u3066\u30b9\u30ad\u30fc\u30de\u9593\u3067\u30c6\u30fc\u30d6\u30eb\u3092\u52b9\u7387\u7684\u306b\u30b3\u30d4\u30fc\u3059\u308b\u624b\u9806\u3092\u8aac\u660e\u3057\u307e\u3059\u3002<\/p>\n\n\n<h2>\u306f\u3058\u3081\u306b<\/h2>\n<p><span style=\"font-family: arial, helvetica, sans-serif\">Amazon Redshift\u306f\u3001\u9ad8\u6027\u80fd\u306a\u30c7\u30fc\u30bf\u30a6\u30a7\u30a2\u30cf\u30a6\u30b9\u30bd\u30ea\u30e5\u30fc\u30b7\u30e7\u30f3\u3068\u3057\u3066\u3001\u591a\u304f\u306e\u4f01\u696d\u3067\u63a1\u7528\u3055\u308c\u3066\u3044\u307e\u3059\u3002\u3057\u304b\u3057\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u904b\u7528\u4e2d\u306b\u30b9\u30ad\u30fc\u30de\u306e\u518d\u7de8\u6210\u304c\u5fc5\u8981\u306b\u306a\u308b\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002\u4f8b\u3048\u3070\u3001\u65b0\u3057\u3044\u30c7\u30fc\u30bf\u30e2\u30c7\u30eb\u306b\u79fb\u884c\u3059\u308b\u969b\u3084\u3001\u65e2\u5b58\u306e\u30c7\u30fc\u30bf\u69cb\u9020\u3092\u6700\u9069\u5316\u3059\u308b\u305f\u3081\u306b\u3001\u30c6\u30fc\u30d6\u30eb\u3092\u5225\u306e\u30b9\u30ad\u30fc\u30de\u306b\u79fb\u52d5\u3059\u308b\u3053\u3068\u304c\u6c42\u3081\u3089\u308c\u308b\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002\u3053\u306e\u8a18\u4e8b\u3067\u306f\u3001Amazon Redshift\u306b\u304a\u3044\u3066\u30b9\u30ad\u30fc\u30de\u9593\u3067\u30c6\u30fc\u30d6\u30eb\u3092\u52b9\u7387\u7684\u306b\u30b3\u30d4\u30fc\u3059\u308b\u624b\u9806\u3092\u8aac\u660e\u3057\u307e\u3059\u3002<\/span><!-- notionvc: e21a2441-ea2a-48bb-a32a-0e341ac142bd --><\/p>\r\n<p><span style=\"font-family: arial, helvetica, sans-serif\">\u500b\u4eba\u60c5\u5831\u3092\u907f\u3051\u308b\u305f\u3081\u3001\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u540d\u3084\u30c6\u30fc\u30d6\u30eb\u540d\u306f\u30d7\u30ec\u30fc\u30b9\u30db\u30eb\u30c0\u3092\u4f7f\u7528\u3057\u3066\u3044\u307e\u3059\u3002<\/span><\/p>\r\n<p><!-- notionvc: e60ff803-4dfd-4acc-8755-ec47e491cf2d --><\/p>\n\n<h2>1. \u65b0\u3057\u3044\u30b9\u30ad\u30fc\u30de\u3092\u4f5c\u6210\u3059\u308b<\/h2>\n<p><span style=\"font-family: arial, helvetica, sans-serif\">\u307e\u305a\u3001\u30c6\u30fc\u30d6\u30eb\u3092\u79fb\u884c\u3059\u308b\u305f\u3081\u306e\u65b0\u3057\u3044\u30b9\u30ad\u30fc\u30de\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002\u3053\u306e\u65b0\u3057\u3044\u30b9\u30ad\u30fc\u30de\u304c\u3001\u65e2\u5b58\u306e\u30b9\u30ad\u30fc\u30de\u304b\u3089\u79fb\u884c\u3055\u308c\u308b\u30c6\u30fc\u30d6\u30eb\u3092\u30db\u30b9\u30c8\u3057\u307e\u3059\u3002<\/span><!-- notionvc: 97e9b7b5-97c6-4c81-8945-bf085b157eb5 --><\/p>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism line-numbers lang-sql\" data-lang=\"SQL\"><code>CREATE SCHEMA new_schema;<\/code><\/pre>\r\n<\/div>\n\n<h2>2. \u30c6\u30fc\u30d6\u30eb\u30b3\u30d4\u30fc\u7528\u306eSQL\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u751f\u6210\u3059\u308b<\/h2>\n<p><span style=\"font-family: arial, helvetica, sans-serif\">\u6b21\u306b\u3001\u5143\u306e\u30b9\u30ad\u30fc\u30de\uff08<span data-token-index=\"1\" class=\"notion-enable-hover\">old_schema<\/span>\uff09\u5185\u306e\u3059\u3079\u3066\u306e\u30c6\u30fc\u30d6\u30eb\u3092\u65b0\u3057\u3044\u30b9\u30ad\u30fc\u30de\uff08<span data-token-index=\"3\" class=\"notion-enable-hover\">new_schema<\/span>\uff09\u306b\u30b3\u30d4\u30fc\u3059\u308b\u305f\u3081\u306eSQL\u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u3092\u751f\u6210\u3057\u307e\u3059\u3002\u4ee5\u4e0b\u306e\u30af\u30a8\u30ea\u3092\u4f7f\u7528\u3057\u3066\u3053\u308c\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002<\/span><!-- notionvc: ae54b629-fd6a-41df-acec-095e6cd9f9d1 --><\/p>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism line-numbers lang-sql\" data-lang=\"SQL\"><code>SELECT\r\n'DROP TABLE IF EXISTS new_schema.' || tablename || '; CREATE TABLE new_schema.' || tablename || ' AS SELECT * FROM old_schema.' || tablename || ';' AS create_table_statement\r\nFROM pg_tables\r\nWHERE schemaname = 'old_schema';<\/code><\/pre>\r\n<\/div>\n\n<h2>3. \u751f\u6210\u3055\u308c\u305fSQL\u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u3092\u5b9f\u884c\u3059\u308b<\/h2>\n<p><span style=\"font-family: arial, helvetica, sans-serif\">\u4e0a\u8a18\u306e\u30af\u30a8\u30ea\u3092\u5b9f\u884c\u3059\u308b\u3068\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306aSQL\u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u304c\u751f\u6210\u3055\u308c\u307e\u3059\u3002<\/span><!-- notionvc: 132e8a3a-0664-4d9d-a503-e853feba0ab8 --><\/p>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism line-numbers lang-sql\" data-lang=\"SQL\"><code>DROP TABLE IF EXISTS new_schema.table1;\r\nCREATE TABLE new_schema.table1 AS SELECT * FROM old_schema.table1;\r\n\r\nDROP TABLE IF EXISTS new_schema.table2;\r\nCREATE TABLE new_schema.table2 AS SELECT * FROM old_schema.table2;\r\n\r\nDROP TABLE IF EXISTS new_schema.table3;\r\nCREATE TABLE new_schema.table3 AS SELECT * FROM old_schema.table3;<\/code><\/pre>\r\n<\/div>\r\n<p><span style=\"font-family: arial, helvetica, sans-serif\">\u3053\u308c\u3089\u306e\u7d50\u679c\u3092\u30b3\u30d4\u30fc\u3057\u3001Redshift\u30b3\u30f3\u30bd\u30fc\u30eb\u3084SQL\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u3067\u5b9f\u884c\u3057\u307e\u3059\u3002<\/span><!-- notionvc: 004e7bbf-81ad-4efe-a90b-4c7cb277569d --><\/p>\n\n<h2>4. \u5143\u306e\u30c6\u30fc\u30d6\u30eb\u3092\u524a\u9664\u3059\u308b<\/h2>\n<p><span style=\"font-family: arial, helvetica, sans-serif\">\u65b0\u3057\u3044\u30b9\u30ad\u30fc\u30de\u306b\u3059\u3079\u3066\u306e\u30c7\u30fc\u30bf\u304c\u6b63\u3057\u304f\u30b3\u30d4\u30fc\u3055\u308c\u305f\u3053\u3068\u3092\u78ba\u8a8d\u3057\u305f\u5f8c\u3001\u5143\u306e\u30c6\u30fc\u30d6\u30eb\u3092\u524a\u9664\u3057\u307e\u3059\u3002<\/span><!-- notionvc: 18f597bb-bbd9-4ef2-8073-c374c0749488 --><\/p>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism line-numbers lang-sql\" data-lang=\"SQL\"><code>DROP TABLE IF EXISTS new_schema.table1;\r\nCREATE TABLE new_schema.table1 AS SELECT * FROM old_schema.table1;\r\n\r\nDROP TABLE IF EXISTS new_schema.table2;\r\nCREATE TABLE new_schema.table2 AS SELECT * FROM old_schema.table2;\r\n\r\nDROP TABLE IF EXISTS new_schema.table3;\r\nCREATE TABLE new_schema.table3 AS SELECT * FROM old_schema.table3;<\/code><\/pre>\r\n<\/div>\r\n<p>&nbsp;<\/p>\r\n<p>&nbsp;<\/p>\r\n<p>&nbsp;<\/p>\r\n<p><!-- notionvc: 140cbb66-024f-4252-bea0-97b39891b6c5 --><\/p>\n\n<h2>5. \u5143\u306e\u30b9\u30ad\u30fc\u30de\u3092\u524a\u9664\u3059\u308b<\/h2>\n<p><span style=\"font-family: arial, helvetica, sans-serif\">\u5fc5\u8981\u306b\u5fdc\u3058\u3066\u3001\u5143\u306e\u30b9\u30ad\u30fc\u30de\u3082\u524a\u9664\u3057\u307e\u3059\u3002<\/span><!-- notionvc: 25133948-38a5-4094-8980-8566d379cdac --><\/p>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism line-numbers lang-sql\" data-lang=\"SQL\"><code>DROP SCHEMA old_schema;<\/code><\/pre>\r\n<\/div>\n\n<h2>\u307e\u3068\u3081<\/h2>\n<p><span style=\"font-family: arial, helvetica, sans-serif\">\u3053\u306e\u624b\u9806\u306b\u5f93\u3046\u3053\u3068\u3067\u3001<span data-token-index=\"1\" class=\"notion-enable-hover\">old_schema<\/span>\u30b9\u30ad\u30fc\u30de\u5185\u306e\u30c6\u30fc\u30d6\u30eb\u3092<span data-token-index=\"3\" class=\"notion-enable-hover\">new_schema<\/span>\u30b9\u30ad\u30fc\u30de\u306b\u52b9\u7387\u7684\u306b\u30b3\u30d4\u30fc\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u30b9\u30ad\u30fc\u30de\u9593\u3067\u30c6\u30fc\u30d6\u30eb\u3092\u79fb\u884c\u3059\u308b\u3053\u3068\u3067\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u6574\u7406\u3084\u6700\u9069\u5316\u304c\u53ef\u80fd\u306b\u306a\u308a\u3001\u30c7\u30fc\u30bf\u7ba1\u7406\u304c\u3088\u308a\u52b9\u7387\u7684\u306b\u306a\u308a\u307e\u3059\u3002<\/span><!-- notionvc: e78137a6-1df3-4d39-8cfc-09aa07a72a73 --><\/p>\r\n<b><span style=\"font-family: arial, helvetica, sans-serif\"><strong>\u6ce8\u610f\u4e8b\u9805<\/strong><\/span><\/b>\r\n<ul>\r\n\t<li><span style=\"font-family: arial, helvetica, sans-serif\">\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3084\u5236\u7d04\u306f\u5225\u9014\u30b3\u30d4\u30fc\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/span><\/li>\r\n\t<li><span style=\"font-family: arial, helvetica, sans-serif\">\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u306e\u7ba1\u7406\u306b\u306f\u6ce8\u610f\u304c\u5fc5\u8981\u3067\u3059\u3002\u30b3\u30d4\u30fc\u4e2d\u306b\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u305f\u5834\u5408\u306b\u5099\u3048\u3066\u3001\u9069\u5207\u306a\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u3092\u53d6\u3063\u3066\u304f\u3060\u3055\u3044\u3002<\/span><\/li>\r\n<\/ul>\r\n<p><!-- notionvc: 161124b5-fb33-4943-93ca-505b850aae60 --><\/p>","protected":false},"excerpt":{"rendered":"<p>Amazon Redshift\u306f\u3001\u9ad8\u6027\u80fd\u306a\u30c7\u30fc\u30bf\u30a6\u30a7\u30a2\u30cf\u30a6\u30b9\u30bd\u30ea\u30e5\u30fc\u30b7\u30e7\u30f3\u3068\u3057\u3066\u3001\u591a\u304f\u306e\u4f01\u696d\u3067\u63a1\u7528\u3055\u308c\u3066\u3044\u307e\u3059\u3002\u3057\u304b\u3057\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u904b\u7528\u4e2d\u306b\u30b9\u30ad\u30fc\u30de\u306e\u518d\u7de8\u6210\u304c\u5fc5\u8981\u306b\u306a\u308b\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002\u4f8b\u3048\u3070\u3001\u65b0\u3057\u3044\u30c7\u30fc\u30bf\u30e2\u30c7\u30eb\u306b\u79fb\u884c\u3059 [&hellip;]<\/p>\n","protected":false},"author":87,"featured_media":4435,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"content-type":"","swell_btn_cv_data":"","footnotes":"","_wp_rev_ctl_limit":""},"categories":[1246],"tags":[201,217,148],"class_list":["post-5019","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-data-infrastructure","tag-aws","tag-redshift","tag-sql"],"_links":{"self":[{"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/posts\/5019","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/users\/87"}],"replies":[{"embeddable":true,"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/comments?post=5019"}],"version-history":[{"count":0,"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/posts\/5019\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/media\/4435"}],"wp:attachment":[{"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/media?parent=5019"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/categories?post=5019"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/tags?post=5019"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}