å¤ãå ã®ç¤¾å åå¼·ä¼ã§ temporal database ã«ã¤ãã¦ç´¹ä»ãã¾ãããçºè¡¨è³æãå ¬éãã¾ãã
Temporal database ã¨ã¯ãæéã®çµéã«ã¨ããªã£ã¦å¤åããæ
å ±ãæ ¼ç´ãããã¼ã¿ãã¼ã¹ã§ããWikipedia è±èªçã«èª¬æãããã¾ãã
en.wikipedia.org
Wikipedia ã®ãã¼ã¸å ã«ããä¾ãåãã¦èª¬æããã¨ããã¨ãã° John ãããæéã«ä½ãã§ããå ´æã以ä¸ã®ãã¼ãã«ã§è¡¨ç¾ãããã¨ãã¾ããJohn 㯠1975 å¹´ 4 æ 3 æ¥ãã Smallville ã«ä½ãã§ãã¦ã1994 å¹´ 8 æ 26 æ¥ã« Bigtown ã«å¼ã£è¶ããã¨ããå ·åã§ããvalid_to ã¯ãã®æ¥ä»ãå«ã¾ãªããã¨ã¨ãã¾ãã
name | address | valid_from | valid_to |
---|---|---|---|
John | Smallville | 1975-04-03 | 1994-08-26 |
John | Bigtown | 1994-08-26 | 2001-04-01 |
ããã§çºçããåé¡ã¯ãvalid_from 㨠valid_to ã®çµãå¨ä½æéãæå³ãã¦ããã¨ããå¶ç´ã表ç¾ã§ããªããã¨ã§ãããã®ãã¼ãã«ã«ã¯ä»¥ä¸ã®ããã«è¡ã追å ã§ãã¦ãã¾ããJohn 㯠1995 å¹´ 6 æ 1 æ¥ãã 2000 å¹´ 9 æ 2 æ¥ã¾ã§ Bigtown 㨠Beachy ã®ä¸¡æ¹ã«ä½ãã§ãããã¨ã«ãªã£ã¦ãã¾ãã¾ãã
name | address | valid_from | valid_to |
---|---|---|---|
John | Smallville | 1975-04-03 | 1994-08-26 |
John | Bigtown | 1994-08-26 | 2001-04-01 |
John | Beachy | 1995-06-01 | 2000-09-03 |
SQL æ¨æºã® SQL:2011 ã§ã¯ããªã¬ã¼ã·ã§ãã«ãã¼ã¿ãã¼ã¹ã§ temporal database ãæ±ãããã®è¨èªæ¡å¼µãè¡ããã¦ãã¾ããSQL:2011 ã§ã¯ä»¥ä¸ã®ããã«è¨è¿°ãããã¨ã§ãvalid_from 㨠valid_to ã®çµãæé (valid_period) ã表ããã¨ãæå®ã§ãã¾ãã
CREATE TABLE person ( name varchar(10), address varchar(10), valid_from date, valid_to date, PERIOD FOR valid_period (valid_from, valid_to), PRIMARY KEY (name, valid_period WITHOUT OVERLAPS) );
ããã«ã以ä¸ã®ãããªã¯ã¨ãªã§ãã¼ãã«ãæ´æ°ã§ãã¾ãããã®ã¯ã¨ãªã§ã¯ãJohn 㯠1995 å¹´ 6 æ 1 æ¥ãã 2000 å¹´ 9 æ 2 æ¥ã¾ã§ Beachy ã«ä½ãã§ããã¨ããæ å ±ãä¸ãã¦ãã¾ãã
UPDATE person FOR PORTION OF valid_period FROM '1995-06-01' TO '2000-09-03' SET address = 'Beachy' WHERE name = 'John';
æåã«ç¤ºãããã¼ãã«ã«å¯¾ãã¦ãã®ã¯ã¨ãªãçºè¡ããã¨ãJohn ã Bigtown ã«ä½ãã§ããæéã®ãã¡ 1995 å¹´ 6 æ 1 æ¥ãã 2000 å¹´ 9 æ 2 æ¥ã®ç¯å²ã®ã¿ãæ´æ°ããããã¼ãã«ã¯ä»¥ä¸ã®ããã«ãªãã¾ãã便å©ã§ããã
name | address | valid_from | valid_to |
---|---|---|---|
John | Smallville | 1975-04-03 | 1994-08-26 |
John | Bigtown | 1994-08-26 | 1995-06-01 |
John | Beachy | 1995-06-01 | 2000-09-03 |
John | Bigtown | 2000-09-03 | 2001-04-01 |
åå¼·ä¼ã§ã¯ããªã¬ã¼ã·ã§ãã«ãã¼ã¿ãã¼ã¹ã§æéæ å ±ãæ±ãæ¹æ³ã¨ãã¦ãMariaDB ã® Temporal Tables 㨠PostgreSQL ã®ç¯å²åãç´¹ä»ãã¾ãããMariaDB ã§ã¯ SQL:2011 ã«æ²¿ã£ãææ³ã§ temporal database ãæ±ãã¾ããPostgreSQL 㯠SQL:2011 ããµãã¼ããã¦ãã¾ããããç¯å²åã使ã£ã¦æéç¯å²ã«é¢ããå¶ç´ãªã©ãè¨è¿°ã§ãã¾ãã
ãªããåå¼·ä¼ã®çºè¡¨è³æã§ã¯ MariaDB ã® timestamp åã®æ大å¤ã 2038-01-19 ã¨ãã¦ãã¾ãããMariaDB 11.5 以éã§ã¯ 2106-02-07 ã¾ã§æ±ããããã«ãªã£ã¦ãã¾ãã
mariadb.com