[28] SQL データベースにおいて日時は重要なデータ型です。 SQL の他の部分と同じように、また他のプラットフォームの日時表現と同じように、 実装ごとに多種多様に取り扱われていて、可搬性はそれほど高くありません。
[3] 特別な値として、日付 0000-00-00
や時刻 00:00:00
、日時
0000-00-00 00:00:00
、年 0000
が使われています。
[4] 2009-00-00
のように月日を 0 としたり、
2009-01-00
のように日を 0 としたりもできます >>2。
[5] 69年までを2000年代、70年からを1900年代として扱います。
[41] PostgreSQL と Oracle では紀元前の表現方法が異なります。
[1] MySQL と PostgreSQL は、先発グレゴリオ暦を採用しています。
[39] Oracle は、最初のグレゴリオ暦への改暦より前は、先発ユリウス暦を採用しています。
標準SQLでは、「"日付時刻リテラル"定義の中で、"日付時刻の値"はグレゴリオ暦に従った日付と時間の自然法則に則る」と明記されています。 PostgreSQLは標準SQLの指針に従い、グレゴリオ暦が使われる以前の年に対してもグレゴリオ暦で日付を数えます。 この規則は先発グレゴリオ暦として知られています。
A calendar applied to dates when it was not actually in use is called proleptic. Thus, if we assume there was never a cutover and Gregorian rules always rule, we have a proleptic Gregorian calendar. This is what is used by MySQL, as is required by standard SQL.
[9] MySQL は tzdata を使っています >>7, >>8。
[10] tzdata の主たる形式の他、閏秒オプション版も提供されています。
[11] tzdata の名前の他に、
システム時間帯を表す SYSTEM
や、
+10:00
や -6:00
のような時差の表記にも対応しています >>8。
[24] PostgreSQL は tzdata と POSIX時間帯を使っています >>23, >>25, >>26。
[37] Oracle はtzdataを使っています >>36。
[17] SQL では時間帯を持たない日時のデータ型が使われることも多いです。 SQL 内での時間帯を持つデータ型との変換時や、 SQL を使うプログラミング言語等での時間帯を持つデータ型との変換時に、 取り扱いに注意が必要となります。
[18] 時間帯を持たない日時のデータ型と Unix time との相互変換の手段が提供されていることがありますが、その場合の Unix time は本来の UTC 基準の値ではなく、地方時基準の値になります。
[13] MySQL の TO_DAYS
は日数、 TO_SECONDS
は秒数を返します。
[15] の秒数は 86400 です >>12。 これは正子を表しているようなので、その1日前からの秒数ということになります。
[22] PostgreSQL は独自の時間形式
(reltime
, timestamp
も参照。) と ISO 8601の時間形式に対応しています
>>23。
[2] MySQL :: MySQL 8.0 Reference Manual :: 12.3 Date and Time Types () https://dev.mysql.com/doc/refman/8.0/en/date-and-time-types.html
[7] MySQL :: Time zone description tables () https://dev.mysql.com/downloads/timezones.html
[8] MySQL :: MySQL 8.0 Reference Manual :: 11.6 MySQL Server Time Zone Support () https://dev.mysql.com/doc/refman/8.0/en/time-zone-support.html
[12] MySQL :: MySQL 8.0 Reference Manual :: 13.7 Date and Time Functions () https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html
[19] PostgreSQL: Documentation: 9.6: Date/Time Types () https://www.postgresql.org/docs/current/static/datatype-datetime.html
[16] PostgreSQL: Documentation: 9.6: Date/Time Functions and Operators () https://www.postgresql.org/docs/current/static/functions-datetime.html
[23] PostgreSQL: Documentation: 9.6: Date/Time Types () https://www.postgresql.org/docs/current/static/datatype-datetime.html
[25] PostgreSQL: Documentation: 9.6: pg_timezone_abbrevs () https://www.postgresql.org/docs/current/static/view-pg-timezone-abbrevs.html
[26] PostgreSQL: Documentation: 9.6: Date/Time Configuration Files () https://www.postgresql.org/docs/current/static/datetime-config-files.html
ISO ISO 8601, SQL standard 1997-12-17 07:37:16-08
SQL traditional style 12/17/1997 07:37:16.00 PST
Postgres original style Wed Dec 17 07:37:16 1997 PST
German regional style 17.12.1997 07:37:16.00 PST
SQL, DMY day/month/year 17/12/1997 15:37:16.00 CET
SQL, MDY month/day/year 12/17/1997 07:37:16.00 PST
Postgres, DMY day/month/year Wed 17 Dec 07:37:16 1997 PST
[29] 日付/時刻型 () https://msdn.microsoft.com/ja-JP/library/ff848733.aspx
For Informatica, the range is limited to 1582-10-15 (October 15, 1582 CE) to 9999-12-31 (December 31, 9999 CE).
January 1, 1753, through December 31, 9999
0001-01-01 through 9999-12-31
1900-01-01 through 2079-06-06
大英帝国では、1752年の9月にユリウス暦からグレゴリオ暦に改暦しています。そのため、1752年9月には19日しか存在しません。改暦を跨いで対応できるようにすると大変なので、Sybase SQL Serverでは、グレゴリオ暦になってからの日付を扱うように、改暦の翌年である1753年を日付時刻型が扱える範囲の開始年としました。そして、それをMicrosoft SQL Serverも引き継いでいる、ということです。
When timestamp values are stored as eight-byte integers (currently the default), microsecond precision is available over the full range of values. When timestamp values are stored as double precision floating-point numbers instead (a deprecated compile-time option), the effective limit of precision might be less than 6. timestamp values are stored as seconds before or after midnight 2000-01-01. When timestamp values are implemented using floating-point numbers, microsecond precision is achieved for dates within a few years of 2000-01-01, but the precision degrades for dates further away. Note that using floating-point datetimes allows a larger range of timestamp values to be represented than shown above: from 4713 BC up to 5874897 AD.
[36] データ型 () https://docs.oracle.com/cd/E57425_01/121/SQLRF/sql_elements001.htm
Oracle はユリウス日 (紀元前4713年1月1日) からの経過日数+秒で日付データ
を管理しています。
紀元前4713年1月1日から2009年3月15日の経過日数は、2454906日です。
こでに、11:42 は (午前とすると) 経過秒は42120秒となります。
1日は、86400 秒なので0.4875 となり、2454906.4875 として格納されます。
[43] datetime (Transact-SQL) - SQL Server | Microsoft Docs (MikeRayMSFT著, ) https://docs.microsoft.com/ja-jp/sql/t-sql/data-types/datetime-transact-sql?view=sql-server-2017
[46] 2.5.4 日時値関数 () https://software.fujitsu.com/jp/manual/manualfiles/M100005/J2X17484/02Z200/J7484-00-02-05-04.html
[47] SQL Differences Between Impala and Hive | 5.6.x | Cloudera Documentation, , https://docs.cloudera.com/documentation/enterprise/5-6-x/topics/impala_langref_unsupported.html#langref_hiveql_semantics
The Impala
TIMESTAMP
type can represent dates ranging from 1400-01-01 to 9999-12-31. This is different from the Hive date range, which is 0000-01-01 to 9999-12-31.