8.5.4. Interval Input

8.5.4.Interval输入

interval values can be written using the following verbose syntax:

interval值输入时的详细语法:

[@] quantity unit [quantity unit...] [direction]

where quantity is a number (possibly signed); unit is microsecond, millisecond, second,minute, hour, day, week, month, year, decade, century, millennium, or abbreviations or plurals of these units; direction can be ago or empty. The at sign (@) is optional noise.The amounts of the different units are implicitly added with appropriate sign accounting. ago negates all the fields. This syntax is also used for interval output, if IntervalStyle is set to postgres_verbose.

quantity是一个数字(可以带符号);unit是microsecond, millisecond, second,minute, hour, day, week, month, year, decade, century, millennium,或者这些unit缩写或复数;direction可以是ago或者为空。符号@是可选的。不同的unit会隐式添加适当的符号。ago会给所有的unit加负号。如果IntervalStyle设为postgres_verbose,则此语法也可用于interval输出。

Quantities of days, hours, minutes, and seconds can be specified without explicit unit markings. For example, '1 12:59:10' is read the same as '1 day 12 hours 59 min 10 sec'. Also,a combination of years and months can be specified with a dash; for example '200-10' is read the same as '200 years 10 months'. (These shorter forms are in fact the only ones allowed by the SQL standard, and are used for output when IntervalStyle is set to sql_standard.)

天、时、分和秒数可以不用显式使用单位限定。例如,'1 12:59:10'与'1 day 12 hours 59 min 10 sec'相同。当然,年和月的混合可以使用“-”号指定,例如'200-10'与'200 years 10 months'相同。(实际上,以上的缩写格式为SQL标准中唯一允许的,当IntervalStyle设为sql_standard时使用。)

Interval values can also be written as ISO 8601 time intervals, using either the “format with designators” of the standard's section 4.4.3.2 or the “alternative format” of section 4.4.3.3. The format with designators looks like this:

也可以将interval值写为ISO 8601的时间间隔值,使用4.4.3.2节(未找到此章节)中的“带有指示符的格式”或者4.4.3.3节(未找到此章节)的“替代格式”。带有指示符的格式类似于:

P quantity unit [ quantity unit ...] [ T [ quantity unit ...]]

The string must start with a P, and may include a T that introduces the time-of-day units. The available unit abbreviations are given in Table 8.16. Units may be omitted, and may be specified in any order,but units smaller than a day must appear after T. In particular, the meaning of M depends on whether it is before or after T.

该字符串必须以P开头,并且可以包含引入时间单位的T。表8.16中给出了可用的单位缩写。单位可以省略,也可以以任何顺序指定,但是小于天的单位必须出现在T后面。特别地,M的含义取决于它是在T之前还是之后。

In the alternative format:

另一种格式:

P [ years-months-days ] [ T hours:minutes:seconds ]

the string must begin with P, and a T separates the date and time parts of the interval. The values are given as numbers similar to ISO 8601 dates.

字符串必须以P开否,以T区分interval的时间和日期部分。值以类似于ISO 8601的数字给出。

When writing an interval constant with a fields specification, or when assigning a string to an interval column that was defined with a fields specification, the interpretation of unmarked quantities depends on the fields. For example INTERVAL '1' YEAR is read as 1 year, whereas INTERVAL '1' means 1 second. Also, field values “to the right” of the least significant field allowed by the fields specification are silently discarded. For example, writing INTERVAL '1 day 2:03:04' HOUR TO MINUTE results in dropping the seconds field, but not the day field.

在使用字段说明编写间隔常量时,或将字符串分配给使用字段说明定义的间隔列时,对于未标记量的解释取决于字段。 例如,INTERVAL'1'YEAR读为1年,而INTERVAL'1'表示1秒。同样,字段规范允许的最低有效字段“右侧”的字段值将被忽略。 例如,INTERVAL'1 day 2:03:04'HOUR TO MINUTE将导致删除秒字段,而不是天字段。

According to the SQL standard all fields of an interval value must have the same sign, so a leading negative sign applies to all fields; for example the negative sign in the interval literal '-1 2:03:04' applies to both the days and hour/minute/second parts. PostgreSQL allows the fields to have different signs, and traditionally treats each field in the textual representation as independently signed, so that the hour/minute/second part is considered positive in this example. If IntervalStyle is set to sql_standard then a leading sign is considered to apply to all fields (but only if no additional signs appear). Otherwise the traditional PostgreSQL interpretation is used. To avoid ambiguity, it's recommended to attach an explicit sign to each field if any field is negative.

根据SQL标准,间隔值的所有字段必须具有相同的符号,因此前导负号适用于所有字段;例如,间隔文字“ -1 2:03:04”中的负号适用于日期和小时/分钟/秒部分。PostgreSQL允许字段具有不同的符号,并且传统上将文本表示形式中的每个字段视为独立的,因此在此示例中,小时/分钟/秒部分被视为正数。如果将IntervalStyle设置为sql_standard,则认为前导符号适用于所有字段(但仅当没有其他符号出现时)。否则,将使用传统的PostgreSQL解释。为避免歧义,如果任何字段为负,建议在每个字段上都显式附加一个符号。

In the verbose input format, and in some fields of the more compact input formats, field values can have fractional parts; for example '1.5 week' or '01:02:03.45'. Such input is converted to the appropriate  number of months, days, and seconds for storage. When this would result in a fractional number of months or days, the fraction is added to the lower-order fields using the conversion factors 1 month = 30 days and 1 day = 24 hours. For example, '1.5 month' becomes 1 month and 15 days. Only seconds will ever be shown as fractional on output.

在详细的输入格式中,以及在某些更紧凑的输入格式的字段中,字段值可以包含小数部分; 例如“ 1.5周”或“ 01:02:03.45”。 此类输入将转换为适当的月数,天数和秒数以进行存储。如果这将导致小数个月或几天,那么该分数将使用1个月= 30天和1天= 24小时的转换因子添加到低阶字段中。 例如,“ 1.5个月”变为1个月15天。 在输出中,仅秒将显示为小数。

Table 8.17 shows some examples of valid interval input.

表8.17为interval输入的几个示例:

Internally interval values are stored as months, days, and seconds. This is done because the number of days in a month varies, and a day can have 23 or 25 hours if a daylight savings time adjustment is involved. The months and days fields are integers while the seconds field can store fractions. Because intervals are usually created from constant strings or timestamp subtraction, this storage method works well in most cases, but can cause unexpected results:

内部间隔值存储为月,天和秒。这样做是因为一个月中的天数不同,并且如果涉及夏令时调整,则一天可以有23或25个小时。 月和日字段是整数,而秒字段可以存储分数。 由于间隔通常是由常量字符串或时间戳减法创建的,因此该存储方法在大多数情况下都可以很好地工作,但是会导致意外的结果:

SELECT EXTRACT(hours from '80 minutes'::interval);

date_part

-----------

1

SELECT EXTRACT(days from '80 hours'::interval);

date_part

-----------

0

Functions justify_days and justify_hours are available for adjusting days and hours that overflow their normal ranges.

函数justify_days和justify_hours可用于调整超出正常范围的天数和小时数。

mydb=# select justify_hours('80 hours'::interval);

justify_hours

-----------------

3 days 08:00:00

(1 row)

8.5.4. Interval Input相关推荐

  1. Greenplum,HAWQ interval parser带来的问题 - TPCH 测试注意啦

    Greenplum,HAWQ interval parser带来的问题 - TPCH 测试注意啦 作者 digoal 日期 2016-10-11 标签 Greenplum , PostgreSQL , ...

  2. 数据结构---各种树模板

    1:Trie 字典树 字典树 又称单词查找树,Trie树,是一种树形结构,是一种哈希树的变种.典型应用是用于统计,排序和保存大量的字符串(但不仅限于字符串),所以经常被搜索引擎系统用于文本词频统计.它 ...

  3. POJ3468--A Simple Problem with Integers--线段树/树状数组 改段求段

    题目描述 You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type ...

  4. JS中定时器setTimeout,setInterval,clearTimeout,clearInterval用法

    setTimeout是指过多久执行,只执行一次 setInterval是指每过多久执行一次 clearTimeout是关闭setTimeout定时器 clearInterval是关闭setInterv ...

  5. A Simple Problem with Integers POJ - 3468(线段树+区间查询+区间修改+建树+懒惰标记模板)+(树状数组)

    题意: 有一个数组,有两种操作.1: Q a b 求[a,b]的和 2:C a b c 给[a,b] 的所有元素都加上c. 题目: You have N integers, A1, A2, ... , ...

  6. 1083. List Grades (25)

    1083. List Grades (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given a l ...

  7. 【POJ - 3468 】 A Simple Problem with Integers (线段树模板 区间更新 + 区间和查询)(不能树状数组或差分数组)

    题干: You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type o ...

  8. k8s与监控--从telegraf改造谈golang多协程精确控制

    从telegraf改造谈golang多协程精确控制 前言 telegraf是infuxdb公司开源出来的一个基于插件机制的收集metrics的 项目.整个架构和elastic公司的日志收集系统极其类似 ...

  9. POJ 3468 线段树+lazy标记

    lazy标记   Time Limit:5000MS     Memory Limit:131072KB     64bit IO Format:%I64d & %I64u  Submit S ...

最新文章

  1. 23 种设计模式的通俗解释
  2. 插入的表单控制下拉框怎么设置_想要告别表单重复填写?这一个功能就够了
  3. Object of type 'ndarray' is not JSON serializable
  4. Linux运维之常见命令
  5. yolov3-tiny神经网络FPGA(ZYNQ7020)实现
  6. 纹理对象纹理单元纹理目标_网页设计理论:纹理
  7. 春节特惠活动┃给孩子讲100个科学道理,不如带他做这些趣味实验!
  8. CF388D-Fox and Perfect Sets【dp,线性基】
  9. 深度学习在搜索业务中的探索与实践 1
  10. Magento: 获取客户信息 Get Customer’s Full Name, First Name, Last Name and Email Addres
  11. SAP License:第三方运输业务的外币付款处理
  12. python爬虫股票数据分析判断股票好坏_教你用Python爬虫股票评论,简单分析股民用户情绪...
  13. “FreeTextBox”控件使用——Word编辑器
  14. 哪些项目适合写进Java程序员面试简历?推荐这10类
  15. Disunity_V0.5.0 提取Unity生成的APK资源的后续探索
  16. Chaos Mesh介绍
  17. 那些一味顺从领导,不与领导顶嘴的人最后结局都怎么样了?
  18. Oracle greatest函数
  19. 商人渡河问题(MATLAB版)
  20. 做seo为什么要了解网站

热门文章

  1. cvm服务器虚拟化,云服务器cvm简单高效便于处理能力提升
  2. 葫芦岛php,葫芦岛php培训
  3. 全球虚拟运营商发展现状与探索
  4. php php_dbase.dll,php – 如何在Windows中解决“调用未定义函数dbase_open()”错误
  5. Windows 8.1新型启动方式“WIMBoot”基础简介以及初步探索
  6. Hibernate与JPA
  7. UOS与Deepin OS区别详解
  8. 数据处理-18.数据采集渠道
  9. 用html5制作一个2d沙发,沙发诞生记——一套沙发的制作工艺及流程
  10. Mothur1进阶_走近Mothur,探索未知