{"id":9942,"date":"2020-03-31T12:26:18","date_gmt":"2020-03-31T03:26:18","guid":{"rendered":"https:\/\/www.itblog.jp\/?p=9942"},"modified":"2020-03-31T12:26:18","modified_gmt":"2020-03-31T03:26:18","slug":"postgressql%e3%81%aetrigger%e3%81%a7%e3%80%81insert%e3%81%99%e3%82%8b%e5%80%a4%e3%82%92insert-before%e3%81%a7%e8%a8%88%e7%ae%97%e3%81%99%e3%82%8b","status":"publish","type":"post","link":"https:\/\/www.itblog.jp\/?p=9942","title":{"rendered":"PostgresSQL\u306eTrigger\u3067\u3001insert\u3059\u308b\u5024\u3092INSERT BEFORE\u3067\u8a08\u7b97\u3059\u308b"},"content":{"rendered":"\n<p>\u95a2\u308f\u3063\u3066\u3044\u305f\u6848\u4ef6\u3067\u3001PostgresSQL\u306eTrigger\u3092\u4f7f\u3063\u3066\u3001Insert\u3059\u308b\u7279\u5b9a\u306e\u30ab\u30e9\u30e0\u5024\u3092\u3001Trigger\u306eInsert Before\u3092\u4f7f\u3063\u3066\u8a08\u7b97\u3057\u3066\u633f\u5165\u3059\u308b\u3068\u3044\u3046\u30b1\u30fc\u30b9\u304c\u3042\u308a\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p>Qiita\u306e\u4ee5\u4e0b\u306e\u8a18\u4e8b\u304c\u308f\u304b\u308a\u3084\u3059\u304b\u3063\u305f\u3067\u3059\u3002<\/p>\n\n\n\n<p>PostgreSQL\u3067\u30c8\u30ea\u30ac\u3092\u4f5c\u6210\u3057\u3001\u540c\u4e00\u30c6\u30fc\u30d6\u30eb\u5185\u306b\u5024\u3092\u8ffd\u52a0\u3059\u308b<\/p>\n\n\n\n<p><a href=\"https:\/\/qiita.com\/grassfield\/items\/60fad9c1d4a8d205bff3\">https:\/\/qiita.com\/grassfield\/items\/60fad9c1d4a8d205bff3<\/a><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">CREATE OR REPLACE FUNCTION culc_totalworktime() RETURNS trigger AS $BODY$\nBEGIN\n  NEW.\u52e4\u52d9\u6642\u9593 := NEW.\u7d42\u4e86\u6642\u523b-NEW.\u958b\u59cb\u6642\u523b-NEW.\u4f11\u61a9\u6642\u9593; -- \u89e3\u8aac\n  RETURN NEW;\nEND;\n$BODY$ LANGUAGE plpgsql VOLATILE COST 100;\nALTER FUNCTION culc_totalworktime() OWNER TO postgres;<\/pre>\n\n\n\n<p>\u4e0a\u8a18\u306e\u3088\u3046\u306a\u304b\u3093\u3058\u3067\u5024\u3092\u8fd4\u3059\u30c8\u30ea\u30ac\u3092\u4f5c\u6210\u3057\u3066<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">CREATE TRIGGER totalworktime_trg\nBEFORE INSERT OR UPDATE ON \u52e4\u52d9\u5b9f\u7e3e\nFOR EACH ROW EXECUTE PROCEDURE culc_totalworktime();<\/pre>\n\n\n\n<p>\u4e0a\u8a18\u306e\u3088\u3046\u306bINSERT BEFORE\u3067\u30c8\u30ea\u30ac\u3092\u547c\u3073\u51fa\u3057\u3066\u3084\u308c\u3070\u3001\u30ab\u30e9\u30e0\u306b\u8a08\u7b97\u3055\u308c\u305f\u5024\u304c\u633f\u5165\u3055\u308c\u307e\u3057\u305f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u95a2\u308f\u3063\u3066\u3044\u305f\u6848\u4ef6\u3067\u3001PostgresSQL\u306eTrigger\u3092\u4f7f\u3063\u3066\u3001Insert\u3059\u308b\u7279\u5b9a\u306e\u30ab\u30e9\u30e0\u5024\u3092\u3001Trigger\u306eInsert Before\u3092\u4f7f\u3063\u3066\u8a08\u7b97\u3057\u3066\u633f\u5165\u3059\u308b\u3068\u3044\u3046\u30b1\u30fc\u30b9\u304c\u3042\u308a\u307e\u3057\u305f\u3002 Qiita\u306e\u4ee5\u4e0b\u306e\u8a18\u4e8b\u304c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[170,131],"tags":[],"class_list":["post-9942","post","type-post","status-publish","format-standard","hentry","category-postgresql","category-131"],"_links":{"self":[{"href":"https:\/\/www.itblog.jp\/index.php?rest_route=\/wp\/v2\/posts\/9942","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.itblog.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.itblog.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.itblog.jp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.itblog.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9942"}],"version-history":[{"count":0,"href":"https:\/\/www.itblog.jp\/index.php?rest_route=\/wp\/v2\/posts\/9942\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.itblog.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9942"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.itblog.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9942"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.itblog.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9942"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}