8.5. Date/Time Types
8.5.日期/时间类型
PostgreSQL supports the full set of SQL date and time types, shown in Table 8.9. The operations
available on these data types are described in Section 9.9. Dates are counted according to the Gregorian
calendar, even in years before that calendar was introduced (see Section B.5 for more information).
PostgreSQL支持完整的SQL日期和时间类型,如表8.9。可用于这些数据类型的操作,在第9.9节讲述。
日期是根据公历计算的,即使是在未采用该日历的年份也是如此(有关更多信息,请参见B.5节)。
Note
注
The SQL standard requires that writing just
timestamp
be equivalent to
timestamp
without time zone
, and PostgreSQL honors that behavior.
timestamptz
is accepted as an abbreviation for
timestamp with time zone
; this
is a PostgreSQL extension.
SQL标准要求timestamp表示timestamp without time zone,PostgreSQL严格的遵守了该要求。作为扩展,PostgreSQL中使用timestampz作为timestamp with time zone的简写。
time
,
timestamp
, and
interval
accept an optional precision value
p
which specifies the number
of fractional digits retained in the seconds field. By default, there is no explicit bound on precision.
The allowed range of
p
is from 0 to 6.
time,timestamp和interval接受可选的精度值p,此值指定在秒字段中保留的小数位数。默认,没有明确的限制。p的允许范围为0到6。
The
interval
type has an additional option, which is to restrict the set of stored fields by writing
one of these phrases:
interval类型
还有一个附加选项,它可以通过编写以下短语之一来限制存储字段的集合:
YEAR
MONTH
DAY
HOUR
MINUTE
SECOND
YEAR TO MONTH
DAY TO HOUR
DAY TO MINUTE
DAY TO SECOND
HOUR TO MINUTE
HOUR TO SECOND
MINUTE TO SECOND
Note that if both
fields
and
p
are specified, the
fields
must include
SECOND
, since the precision
applies only to the seconds.
注意,如果同时限定了fields和p,那么fields中必须包含second,因为p仅适用于秒。
The type
time with time zone
is defined by the SQL standard, but the definition exhibits properties
which lead to questionable usefulness. In most cases, a combination of
date
,
time
,
timestamp
without time zone
, and
timestamp with time zone
should provide a complete
range of date/time functionality required by any application.
time with time zone时间类型是由SQL标准定义的,但是该定义显示的属性其实用性存在问题。在大多数情况下,date,time,timestamp without time zone和timestamp with time zone的组合使用即可满足应用程序对于日期时间功能的需求。
The types
abstime
and
reltime
are lower precision types which are used internally. You are
discouraged from using these types in applications; these internal types might disappear in a future
release.
abstime和reltime是内部使用的低精度数据类型。不要在应用程序中使用此理性,因为在未来的版本中,可能会丢弃这两种类型。