Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita4917be

Browse files
committed
Add support for input and output of interval values formatted per ISO 8601;
specifically, we can input either the "format with designators" or the"alternative format", and we can output the former when IntervalStyle is setto iso_8601.Ron Mayer
1 parenta44564b commita4917be

File tree

11 files changed

+605
-34
lines changed

11 files changed

+605
-34
lines changed

‎doc/src/sgml/config.sgml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.194 2008/11/09 00:28:34 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.195 2008/11/11 02:42:31 tgl Exp $ -->
22

33
<chapter Id="runtime-config">
44
<title>Server Configuration</title>
@@ -4032,6 +4032,9 @@ SET XML OPTION { DOCUMENT | CONTENT };
40324032
matching <productname>PostgreSQL</> releases prior to 8.4
40334033
when the <varname>DateStyle</>
40344034
parameter was set to non-<literal>ISO</> output.
4035+
The value <literal>iso_8601</> will produce output matching the time
4036+
interval <quote>format with designators</> defined in section
4037+
4.4.3.2 of ISO 8601.
40354038
</para>
40364039
<para>
40374040
The <varname>IntervalStyle</> parameter also affects the

‎doc/src/sgml/datatype.sgml

Lines changed: 127 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/datatype.sgml,v 1.233 2008/11/09 17:09:48 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/datatype.sgml,v 1.234 2008/11/11 02:42:31 tgl Exp $ -->
22

33
<chapter id="datatype">
44
<title id="datatype-title">Data Types</title>
@@ -2353,9 +2353,9 @@ January 8 04:05:06 1999 PST
23532353
<type>interval</type> values can be written with the following
23542354
verbose syntax:
23552355

2356-
<programlisting>
2356+
<synopsis>
23572357
<optional>@</> <replaceable>quantity</> <replaceable>unit</> <optional><replaceable>quantity</> <replaceable>unit</>...</> <optional><replaceable>direction</></optional>
2358-
</programlisting>
2358+
</synopsis>
23592359

23602360
where <replaceable>quantity</> is a number (possibly signed);
23612361
<replaceable>unit</> is <literal>microsecond</literal>,
@@ -2384,6 +2384,76 @@ January 8 04:05:06 1999 PST
23842384
<varname>IntervalStyle</> is set to <literal>sql_standard</literal>.)
23852385
</para>
23862386

2387+
<para>
2388+
Interval values can also be written as ISO 8601 time intervals, using
2389+
either the <quote>format with designators</> of the standard's section
2390+
4.4.3.2 or the <quote>alternative format</> of section 4.4.3.3. The
2391+
format with designators looks like this:
2392+
<synopsis>
2393+
P <replaceable>quantity</> <replaceable>unit</> <optional> <replaceable>quantity</> <replaceable>unit</> ...</optional> <optional> T <optional> <replaceable>quantity</> <replaceable>unit</> ...</optional></optional>
2394+
</synopsis>
2395+
The string must start with a <literal>P</>, and may include a
2396+
<literal>T</> that introduces the time-of-day units. The
2397+
available unit abbreviations are given in <xref
2398+
linkend="datatype-interval-iso8601-units">. Units may be
2399+
omitted, and may be specified in any order, but units smaller than
2400+
a day must appear after <literal>T</>. In particular, the meaning of
2401+
<literal>M</> depends on whether it is before or after
2402+
<literal>T</>.
2403+
</para>
2404+
2405+
<table id="datatype-interval-iso8601-units">
2406+
<title>ISO 8601 interval unit abbreviations</title>
2407+
<tgroup cols="2">
2408+
<thead>
2409+
<row>
2410+
<entry>Abbreviation</entry>
2411+
<entry>Meaning</entry>
2412+
</row>
2413+
</thead>
2414+
<tbody>
2415+
<row>
2416+
<entry>Y</entry>
2417+
<entry>Years</entry>
2418+
</row>
2419+
<row>
2420+
<entry>M</entry>
2421+
<entry>Months (in the date part)</entry>
2422+
</row>
2423+
<row>
2424+
<entry>W</entry>
2425+
<entry>Weeks</entry>
2426+
</row>
2427+
<row>
2428+
<entry>D</entry>
2429+
<entry>Days</entry>
2430+
</row>
2431+
<row>
2432+
<entry>H</entry>
2433+
<entry>Hours</entry>
2434+
</row>
2435+
<row>
2436+
<entry>M</entry>
2437+
<entry>Minutes (in the time part)</entry>
2438+
</row>
2439+
<row>
2440+
<entry>S</entry>
2441+
<entry>Seconds</entry>
2442+
</row>
2443+
</tbody>
2444+
</tgroup>
2445+
</table>
2446+
2447+
<para>
2448+
In the alternative format:
2449+
<synopsis>
2450+
P <optional> <replaceable>years</>-<replaceable>months</>-<replaceable>days</> </optional> <optional> T <replaceable>hours</>:<replaceable>minutes</>:<replaceable>seconds</> </optional>
2451+
</synopsis>
2452+
the string must begin with <literal>P</literal>, and a
2453+
<literal>T</> separates the date and time parts of the interval.
2454+
The values are given as numbers similar to ISO 8601 dates.
2455+
</para>
2456+
23872457
<para>
23882458
When writing an interval constant with a <replaceable>fields</>
23892459
specification, or when assigning to an interval column that was defined
@@ -2433,6 +2503,46 @@ January 8 04:05:06 1999 PST
24332503
For example, <literal>'1.5 month'</> becomes 1 month and 15 days.
24342504
Only seconds will ever be shown as fractional on output.
24352505
</para>
2506+
2507+
<para>
2508+
<xref linkend="datatype-interval-input-examples"> shows some examples
2509+
of valid <type>interval</> input.
2510+
</para>
2511+
2512+
<table id="datatype-interval-input-examples">
2513+
<title>Interval Input</title>
2514+
<tgroup cols="2">
2515+
<thead>
2516+
<row>
2517+
<entry>Example</entry>
2518+
<entry>Description</entry>
2519+
</row>
2520+
</thead>
2521+
<tbody>
2522+
<row>
2523+
<entry>1-2</entry>
2524+
<entry>SQL standard format: 1 year 2 months</entry>
2525+
</row>
2526+
<row>
2527+
<entry>3 4:05:06</entry>
2528+
<entry>SQL standard format: 3 days 4 hours 5 minutes 6 seconds</entry>
2529+
</row>
2530+
<row>
2531+
<entry>1 year 2 months 3 days 4 hours 5 minutes 6 seconds</entry>
2532+
<entry>Traditional Postgres format: 1 year 2 months 3 days 4 hours 5 minutes 6 seconds</entry>
2533+
</row>
2534+
<row>
2535+
<entry>P1Y2M3DT4H5M6S</entry>
2536+
<entry>ISO 8601 <quote>format with designators</>: same meaning as above</entry>
2537+
</row>
2538+
<row>
2539+
<entry>P0001-02-03T04:05:06</entry>
2540+
<entry>ISO 8601 <quote>alternative format</>: same meaning as above</entry>
2541+
</row>
2542+
</tbody>
2543+
</tgroup>
2544+
</table>
2545+
24362546
</sect2>
24372547

24382548
<sect2 id="datatype-interval-output">
@@ -2446,8 +2556,8 @@ January 8 04:05:06 1999 PST
24462556

24472557
<para>
24482558
The output format of the interval type can be set to one of the
2449-
three styles <literal>sql_standard</>,
2450-
<literal>postgres</>, or <literal>postgres_verbose</>,
2559+
four styles <literal>sql_standard</>, <literal>postgres</>,
2560+
<literal>postgres_verbose</>, or <literal>iso_8601</>,
24512561
using the command <literal>SET intervalstyle</literal>.
24522562
The default is the <literal>postgres</> format.
24532563
<xref linkend="interval-style-output-table"> shows examples of each
@@ -2476,6 +2586,12 @@ January 8 04:05:06 1999 PST
24762586
<varname>DateStyle</> parameter was set to non-<literal>ISO</> output.
24772587
</para>
24782588

2589+
<para>
2590+
The output of the <literal>iso_8601</> style matches the <quote>format
2591+
with designators</> described in section 4.4.3.2 of the
2592+
ISO 8601 standard.
2593+
</para>
2594+
24792595
<table id="interval-style-output-table">
24802596
<title>Interval Output Style Examples</title>
24812597
<tgroup cols="4">
@@ -2506,6 +2622,12 @@ January 8 04:05:06 1999 PST
25062622
<entry>@ 3 days 4 hours 5 mins 6 secs</entry>
25072623
<entry>@ 1 year 2 mons -3 days 4 hours 5 mins 6 secs ago</entry>
25082624
</row>
2625+
<row>
2626+
<entry><literal>iso_8601</></entry>
2627+
<entry>P1Y2M</entry>
2628+
<entry>P3DT4H5M6S</entry>
2629+
<entry>P-1Y-2M3DT-4H-5M-6S</entry>
2630+
</row>
25092631
</tbody>
25102632
</tgroup>
25112633
</table>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp