{"id":2762,"date":"2018-09-18T14:09:38","date_gmt":"2018-09-18T05:09:38","guid":{"rendered":"https:\/\/www.ecomottblog.com\/?p=2762"},"modified":"2018-10-11T10:29:43","modified_gmt":"2018-10-11T01:29:43","slug":"postgresql-%e3%83%88%e3%83%aa%e3%82%ac%e3%83%bc%e3%81%a7%e5%a4%96%e9%83%a8%e3%83%97%e3%83%ad%e3%82%b0%e3%83%a9%e3%83%a0%e3%82%92%e5%ae%9f%e8%a1%8c%e3%81%99%e3%82%8b%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/test.ecomottblog.com\/?p=2762","title":{"rendered":"PostgreSQL \u30c8\u30ea\u30ac\u30fc\u3067\u5916\u90e8\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u5b9f\u884c\u3059\u308b\u65b9\u6cd5"},"content":{"rendered":"<p>\u4ee5\u524d\u6295\u7a3f\u3057\u305f<\/p>\n<blockquote class=\"wp-embedded-content\" data-secret=\"Y9FxwSoRr8\"><p><a href=\"https:\/\/www.ecomottblog.com\/?p=1419\">PostgreSQL SQL\u3067\u5916\u90e8\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u5b9f\u884c\u3059\u308b\u65b9\u6cd5<\/a><\/p><\/blockquote>\n<p><iframe class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;PostgreSQL SQL\u3067\u5916\u90e8\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u5b9f\u884c\u3059\u308b\u65b9\u6cd5&#8221; &#8212; ecomott blog\" src=\"https:\/\/www.ecomottblog.com\/?p=1419&#038;embed=true#?secret=I2WImikuGg#?secret=Y9FxwSoRr8\" data-secret=\"Y9FxwSoRr8\" width=\"500\" height=\"282\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><br \/>\n\u306e\u7d9a\u304d\u3067\u3059\u3002<br \/>\n<!--more--><\/p>\n<p>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u5909\u66f4\u306f\u51fa\u6765\u308b\u304c\u3001\u30d7\u30ed\u30b0\u30e9\u30e0\u306f\u5909\u66f4\u51fa\u6765\u306a\u3044\u30b7\u30b9\u30c6\u30e0\u3068\u306e\u9023\u643a\u3067<br \/>\n\u3042\u308b\u30c6\u30fc\u30d6\u30eb\u306e\u3042\u308b\u30ab\u30e9\u30e0\u304c\u5909\u66f4\u3055\u308c\u305f\u5834\u5408\u306b\u5b9f\u884c\u3057\u305f\u3044\u51e6\u7406\u304c\u3042\u308b\u304c\u3069\u3046\u3057\u3088\u3046\u304b\u3068\u306a\u3063\u305f\u969b\u3001\u30c8\u30ea\u30ac\u30fc\u3092\u5229\u7528\u3059\u308b\u3053\u3068\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u4ee5\u524d\u8a18\u4e8b\u306b\u3057\u305fCOPY\u30b3\u30de\u30f3\u30c9\u3067\u5916\u90e8\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u5229\u7528\u3059\u308bPROGRAM\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u5229\u7528\u3057\u307e\u3059\u3002<\/p>\n<p>\u307e\u305aCOPY\u5148\u30c6\u30fc\u30d6\u30eb\u3068\u3057\u3066\u9069\u5f53\u306a\u30c6\u30fc\u30d6\u30eb\u3092\u7528\u610f\u3057\u307e\u3059\u3002<\/p>\n<pre><code class=\"shell\">CREATE TABLE empty_table (col1 text);\n<\/code><\/pre>\n<p>\u66f4\u65b0\u3055\u308c\u308b\u30c6\u30fc\u30d6\u30eb\u3092\u7528\u610f\u3057\u307e\u3059\u3002<\/p>\n<pre><code class=\"shell\">database# CREATE TABLE update_table (col1 integer);\n<\/code><\/pre>\n<p>update_table\u304c\u66f4\u65b0\u3055\u308c\u305f\u5834\u5408\u306b\u52d5\u4f5c\u3055\u305b\u308b\u30d7\u30ed\u30b7\u30b8\u30e3\u30fc\u3092\u4f5c\u308a\u307e\u3059\u3002<br \/>\npgsql\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306e\u30d5\u30a1\u30a4\u30eb\u4e00\u89a7\u3092\u30c6\u30ad\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u306b\u51fa\u529b\u3059\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<pre><code class=\"shell\">CREATE OR REPLACE FUNCTION program_run() RETURNS trigger AS $BODY$\nDECLARE\n  command_string varchar;\nBEGIN\n  command_string := 'ls \/usr\/local\/pgsql &gt; ~\/hoge_oldval_'||OLD.col1||'_newval_'||new.col1||'.txt';\n  EXECUTE 'COPY empty_table FROM PROGRAM '''|| command_string ||'''';\nRETURN NEW;\nEND;\n$BODY$ LANGUAGE plpgsql VOLATILE COST 100;\n<\/code><\/pre>\n<p>\u30b7\u30f3\u30b0\u30eb\u30af\u30a9\u30fc\u30c8\u306e\u30a8\u30b9\u30b1\u30fc\u30d7\u3067\u898b\u306b\u304f\u3044\u3067\u3059\u306d\u3002<\/p>\n<p>\u4e0a\u8a18\u3092update_table\u304c\u66f4\u65b0\u3055\u308c\u305f\u3089\u52d5\u4f5c\u3059\u308b\u3088\u3046\u306b\u30c8\u30ea\u30ac\u30fc\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<pre><code class=\"shell\">CREATE TRIGGER program_run_trg\nBEFORE UPDATE ON update_table\nFOR EACH ROW EXECUTE PROCEDURE program_run();\n<\/code><\/pre>\n<p>\u5b9f\u969b\u52d5\u304b\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<pre><code class=\"shell\">INSERT INTO update_table VALUES (1);\n<\/code><\/pre>\n<p>\u3053\u306e\u6642\u70b9\u3067\u306f\u30c6\u30ad\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u306f\u4f5c\u6210\u3055\u308c\u307e\u305b\u3093\u3002<\/p>\n<pre><code class=\"shell\">UPDATE update_table SET col1 = 2;\n<\/code><\/pre>\n<p>\u66f4\u65b0\u3057\u305f\u306e\u3067\u30db\u30fc\u30e0\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u4e0b\u8a18\u540d\u79f0\u306e\u30c6\u30ad\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u304c\u4f5c\u6210\u3055\u308c\u307e\u3057\u305f\u3002<br \/>\nhoge_oldval_1_newval_2.txt<\/p>\n<p>\u30ed\u30fc\u30eb\u30d0\u30c3\u30af\u3057\u3066\u3082\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u5b9f\u884c\u3092\u53d6\u308a\u6d88\u3059\u3053\u3068\u306f\u51fa\u6765\u306a\u3044\u306e\u3067\u305d\u3053\u306f\u6ce8\u610f\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4ee5\u524d\u6295\u7a3f\u3057\u305f PostgreSQL SQL\u3067\u5916\u90e8\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u5b9f\u884c\u3059\u308b\u65b9\u6cd5 \u306e\u7d9a\u304d\u3067\u3059\u3002<\/p>\n","protected":false},"author":20,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27],"tags":[],"_links":{"self":[{"href":"https:\/\/test.ecomottblog.com\/index.php?rest_route=\/wp\/v2\/posts\/2762"}],"collection":[{"href":"https:\/\/test.ecomottblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/test.ecomottblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/test.ecomottblog.com\/index.php?rest_route=\/wp\/v2\/users\/20"}],"replies":[{"embeddable":true,"href":"https:\/\/test.ecomottblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2762"}],"version-history":[{"count":4,"href":"https:\/\/test.ecomottblog.com\/index.php?rest_route=\/wp\/v2\/posts\/2762\/revisions"}],"predecessor-version":[{"id":2802,"href":"https:\/\/test.ecomottblog.com\/index.php?rest_route=\/wp\/v2\/posts\/2762\/revisions\/2802"}],"wp:attachment":[{"href":"https:\/\/test.ecomottblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2762"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/test.ecomottblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2762"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/test.ecomottblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2762"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}