Commit 4bbcad1e authored by Thomas G. Lockhart's avatar Thomas G. Lockhart

Update some info, especially the CIDR/INET data types.

parent a6757f2c
<Chapter Id="datatype"> <chapter id="datatype">
<Title>Data Types</Title> <title>Data Types</title>
<Abstract> <abstract>
<Para> <para>
Describes the built-in data types available in Describes the built-in data types available in
<ProductName>Postgres</ProductName>. <productname>Postgres</productname>.
</Para> </para>
</Abstract> </abstract>
<Para> <para>
<ProductName>Postgres</ProductName> has a rich set of native data <productname>Postgres</productname> has a rich set of native data
types available to users. types available to users.
Users may add new types to <ProductName>Postgres</ProductName> using the Users may add new types to <productname>Postgres</productname> using the
<Command>define type</Command> <command>DEFINE TYPE</command>
command described elsewhere. command described elsewhere.
</para>
<Para> <para>
In the context of data types, the following sections will discuss In the context of data types, the following sections will discuss
<acronym>SQL</acronym> standards compliance, porting issues, and usage. <acronym>SQL</acronym> standards compliance, porting issues, and usage.
Some <ProductName>Postgres</ProductName> types correspond directly to Some <productname>Postgres</productname> types correspond directly to
<acronym>SQL92</acronym>-compatible types. In other <acronym>SQL92</acronym>-compatible types. In other
cases, data types defined by <acronym>SQL92</acronym> syntax are mapped directly cases, data types defined by <acronym>SQL92</acronym> syntax are mapped directly
into native <ProductName>Postgres</ProductName> types. into native <productname>Postgres</productname> types.
Many of the built-in types have obvious external formats. However, several Many of the built-in types have obvious external formats. However, several
types are either unique to <ProductName>Postgres</ProductName>, types are either unique to <productname>Postgres</productname>,
such as open and closed paths, or have such as open and closed paths, or have
several possibilities for formats, such as date and time types. several possibilities for formats, such as the date and time types.
</Para> </para>
<Para> <para>
<TABLE TOCENTRY="1"> <table tocentry="1">
<TITLE><ProductName>Postgres</ProductName> Data Types</TITLE> <title><productname>Postgres</productname> Data Types</title>
<TITLEABBREV>Data Types</TITLEABBREV> <titleabbrev>Data Types</titleabbrev>
<TGROUP COLS="3"> <tgroup cols="3">
<THEAD> <thead>
<ROW> <row>
<ENTRY><ProductName>Postgres</ProductName> Type</ENTRY> <entry><productname>Postgres</productname> Type</entry>
<ENTRY><Acronym>SQL92</Acronym> or <Acronym>SQL3</Acronym> Type</ENTRY> <entry><acronym>SQL92</acronym> or <acronym>SQL3</acronym> Type</entry>
<ENTRY>Description</ENTRY> <entry>Description</entry>
</ROW> </row>
</THEAD> </thead>
<TBODY> <tbody>
<ROW> <row>
<ENTRY>bool</ENTRY> <entry>bool</entry>
<ENTRY>boolean</ENTRY> <entry>boolean</entry>
<ENTRY>logical boolean (true/false)</ENTRY> <entry>logical boolean (true/false)</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>box</ENTRY> <entry>box</entry>
<ENTRY></ENTRY> <entry></entry>
<ENTRY>rectangular box in 2D plane</ENTRY> <entry>rectangular box in 2D plane</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>char(n)</ENTRY> <entry>char(n)</entry>
<ENTRY>character(n)</ENTRY> <entry>character(n)</entry>
<ENTRY>fixed-length character string</ENTRY> <entry>fixed-length character string</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>cidr</ENTRY> <entry>cidr</entry>
<ENTRY></ENTRY> <entry></entry>
<ENTRY>IP version 4 network or host address</ENTRY> <entry>IP version 4 network or host address</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>circle</ENTRY> <entry>circle</entry>
<ENTRY></ENTRY> <entry></entry>
<ENTRY>circle in 2D plane</ENTRY> <entry>circle in 2D plane</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>date</ENTRY> <entry>date</entry>
<ENTRY>date</ENTRY> <entry>date</entry>
<ENTRY>calendar date without time of day</ENTRY> <entry>calendar date without time of day</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>float4/8</ENTRY> <entry>float4/8</entry>
<ENTRY>float(p)</ENTRY> <entry>float(p)</entry>
<ENTRY>floating-point number with precision p</ENTRY> <entry>floating-point number with precision p</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>float8</ENTRY> <entry>float8</entry>
<ENTRY>real, double precision</ENTRY> <entry>real, double precision</entry>
<ENTRY>double-precision floating-point number</ENTRY> <entry>double-precision floating-point number</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>inet</ENTRY> <entry>inet</entry>
<ENTRY></ENTRY> <entry></entry>
<ENTRY>IP version 4 network or host address</ENTRY> <entry>IP version 4 network or host address</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>int2</ENTRY> <entry>int2</entry>
<ENTRY>smallint</ENTRY> <entry>smallint</entry>
<ENTRY>signed two-byte integer</ENTRY> <entry>signed two-byte integer</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>int4</ENTRY> <entry>int4</entry>
<ENTRY>int, integer</ENTRY> <entry>int, integer</entry>
<ENTRY>signed 4-byte integer</ENTRY> <entry>signed 4-byte integer</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>int4</ENTRY> <entry>int4</entry>
<ENTRY>decimal(p,s)</ENTRY> <entry>decimal(p,s)</entry>
<ENTRY>exact numeric for p <= 9, s = 0</ENTRY> <entry>exact numeric for p <= 9, s = 0</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>int4</ENTRY> <entry>int4</entry>
<ENTRY>numeric(p,s)</ENTRY> <entry>numeric(p,s)</entry>
<ENTRY>exact numeric for p == 9, s = 0</ENTRY> <entry>exact numeric for p == 9, s = 0</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>int8</ENTRY> <entry>int8</entry>
<ENTRY></ENTRY> <entry></entry>
<ENTRY>signed 8-byte integer</ENTRY> <entry>signed 8-byte integer</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>line</ENTRY> <entry>line</entry>
<ENTRY></ENTRY> <entry></entry>
<ENTRY>infinite line in 2D plane</ENTRY> <entry>infinite line in 2D plane</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>lseg</ENTRY> <entry>lseg</entry>
<ENTRY></ENTRY> <entry></entry>
<ENTRY>line segment in 2D plane</ENTRY> <entry>line segment in 2D plane</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>money</ENTRY> <entry>money</entry>
<ENTRY>decimal(9,2)</ENTRY> <entry>decimal(9,2)</entry>
<ENTRY>US-style currency</ENTRY> <entry>US-style currency</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>path</ENTRY> <entry>path</entry>
<ENTRY></ENTRY> <entry></entry>
<ENTRY>open and closed geometric path in 2D plane</ENTRY> <entry>open and closed geometric path in 2D plane</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>point</ENTRY> <entry>point</entry>
<ENTRY></ENTRY> <entry></entry>
<ENTRY>geometric point in 2D plane</ENTRY> <entry>geometric point in 2D plane</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>polygon</ENTRY> <entry>polygon</entry>
<ENTRY></ENTRY> <entry></entry>
<ENTRY>closed geometric path in 2D plane</ENTRY> <entry>closed geometric path in 2D plane</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>serial</ENTRY> <entry>serial</entry>
<ENTRY></ENTRY> <entry></entry>
<ENTRY>unique id for indexing and cross-reference</ENTRY> <entry>unique id for indexing and cross-reference</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>time</ENTRY> <entry>time</entry>
<ENTRY>time</ENTRY> <entry>time</entry>
<ENTRY>time of day</ENTRY> <entry>time of day</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>timespan</ENTRY> <entry>timespan</entry>
<ENTRY>interval</ENTRY> <entry>interval</entry>
<ENTRY>general-use time span</ENTRY> <entry>general-use time span</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>timestamp</ENTRY> <entry>timestamp</entry>
<ENTRY>timestamp with time zone</ENTRY> <entry>timestamp with time zone</entry>
<ENTRY>date/time</ENTRY> <entry>date/time</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>varchar(n)</ENTRY> <entry>varchar(n)</entry>
<ENTRY>character varying(n)</ENTRY> <entry>character varying(n)</entry>
<ENTRY>variable-length character string</ENTRY> <entry>variable-length character string</entry>
</ROW> </row>
</TBODY> </tbody>
</TGROUP> </tgroup>
</TABLE> </table>
</Para> </para>
<para> <para>
<note> <note>
<para> <para>
The <type>cidr</type> and <type>inet</type> types are designed to handle any IP type The <type>cidr</type> and <type>inet</type> types are designed to handle any IP type
but only ipv4 is handled in the current implementation. but only ipv4 is handled in the current implementation.
Everything here that talks about ipv4 will apply to ipv6 in a future release. Everything here that talks about ipv4 will apply to ipv6 in a future release.</para>
</note> </note></para>
<para>
<table tocentry="1">
<title><productname>Postgres</productname> Function Constants</title>
<titleabbrev>Constants</titleabbrev>
<tgroup cols="3">
<thead>
<row>
<entry><productname>Postgres</productname> Function</entry>
<entry><acronym>SQL92</acronym> Constant</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry>getpgusername()</entry>
<entry>current_user</entry>
<entry>user name in current session</entry>
</row>
<row>
<entry>date('now')</entry>
<entry>current_date</entry>
<entry>date of current transaction</entry>
</row>
<row>
<entry>time('now')</entry>
<entry>current_time</entry>
<entry>time of current transaction</entry>
</row>
<row>
<entry>timestamp('now')</entry>
<entry>current_timestamp</entry>
<entry>date and time of current transaction</entry>
</row>
</tbody>
</tgroup>
</table>
</para>
<Para> <para>
<TABLE TOCENTRY="1"> <productname>Postgres</productname> has features at the forefront of
<TITLE><ProductName>Postgres</ProductName> Function Constants</TITLE>
<TITLEABBREV>Constants</TITLEABBREV>
<TGROUP COLS="3">
<THEAD>
<ROW>
<ENTRY><ProductName>Postgres</ProductName> Function</ENTRY>
<ENTRY><Acronym>SQL92</Acronym> Constant</ENTRY>
<ENTRY>Description</ENTRY>
</ROW>
</THEAD>
<TBODY>
<ROW>
<ENTRY>getpgusername()</ENTRY>
<ENTRY>current_user</ENTRY>
<ENTRY>user name in current session</ENTRY>
</ROW>
<ROW>
<ENTRY>date('now')</ENTRY>
<ENTRY>current_date</ENTRY>
<ENTRY>date of current transaction</ENTRY>
</ROW>
<ROW>
<ENTRY>time('now')</ENTRY>
<ENTRY>current_time</ENTRY>
<ENTRY>time of current transaction</ENTRY>
</ROW>
<ROW>
<ENTRY>timestamp('now')</ENTRY>
<ENTRY>current_timestamp</ENTRY>
<ENTRY>date and time of current transaction</ENTRY>
</ROW>
</TBODY>
</TGROUP>
</TABLE>
</Para>
<Para>
<ProductName>Postgres</ProductName> has features at the forefront of
<acronym>ORDBMS</acronym> development. In addition to <acronym>ORDBMS</acronym> development. In addition to
<acronym>SQL3</acronym> conformance, substantial portions <acronym>SQL3</acronym> conformance, substantial portions
of <acronym>SQL92</acronym> are also supported. of <acronym>SQL92</acronym> are also supported.
Although we strive for <acronym>SQL92</acronym> compliance, Although we strive for <acronym>SQL92</acronym> compliance,
there are some aspects of the standard there are some aspects of the standard
which are ill considered and which should not live through subsequent standards. which are ill considered and which should not live through subsequent standards.
<ProductName>Postgres</ProductName> will not make great efforts to <productname>Postgres</productname> will not make great efforts to
conform to these features; however, these tend to apply in little-used conform to these features; however, these tend to apply in little-used
or obsure cases, and a typical user is not likely to run into them. or obsure cases, and a typical user is not likely to run into them.</para>
<Para> <para>
Most of the input and output functions corresponding to the Most of the input and output functions corresponding to the
base types (e.g., integers and floating point numbers) do some base types (e.g., integers and floating point numbers) do some
error-checking. error-checking.
...@@ -240,91 +241,92 @@ addition and multiplication) do not perform run-time error-checking in the ...@@ -240,91 +241,92 @@ addition and multiplication) do not perform run-time error-checking in the
interests of improving execution speed. interests of improving execution speed.
On some systems, for example, the numeric operators for some data types may On some systems, for example, the numeric operators for some data types may
silently underflow or overflow. silently underflow or overflow.
</Para> </para>
<Para> <para>
Note that some of the input and output functions are not invertible. That is, Note that some of the input and output functions are not invertible. That is,
the result of an output function may lose precision when compared to the result of an output function may lose precision when compared to
the original input. the original input.
<note> <note>
<para> <para>
The original <ProductName>Postgres</ProductName> v4.2 code received from The original <productname>Postgres</productname> v4.2 code received from
Berkeley rounded all double precision floating point results to six digits for Berkeley rounded all double precision floating point results to six digits for
output. Starting with v6.1, floating point numbers are allowed to retain output. Starting with v6.1, floating point numbers are allowed to retain
most of the intrinsic precision of the type (typically 15 digits for doubles, most of the intrinsic precision of the type (typically 15 digits for doubles,
6 digits for 4-byte floats). 6 digits for 4-byte floats).
Other types with underlying floating point fields (e.g. geometric Other types with underlying floating point fields (e.g. geometric
types) carry similar precision. types) carry similar precision.</para>
</note> </note>
</Para> </para>
<Sect1> <sect1>
<Title>Numeric Types</Title> <title>Numeric Types</title>
<Para> <para>
Numeric types consist of two- and four-byte integers and four- and eight-byte Numeric types consist of two- and four-byte integers and four- and eight-byte
floating point numbers. floating point numbers.</para>
<Para> <para>
<TABLE TOCENTRY="1"> <table tocentry="1">
<TITLE><ProductName>Postgres</ProductName> Numeric Types</TITLE> <title><productname>Postgres</productname> Numeric Types</title>
<TITLEABBREV>Numerics</TITLEABBREV> <titleabbrev>Numerics</titleabbrev>
<TGROUP COLS="4"> <tgroup cols="4">
<THEAD> <thead>
<ROW> <row>
<ENTRY>Numeric Type</ENTRY> <entry>Numeric Type</entry>
<ENTRY>Storage</ENTRY> <entry>Storage</entry>
<ENTRY>Description</ENTRY> <entry>Description</entry>
<ENTRY>Range</ENTRY> <entry>Range</entry>
</ROW> </row>
</THEAD> </thead>
<TBODY> <tbody>
<ROW> <row>
<ENTRY>float4</ENTRY> <entry>float4</entry>
<ENTRY>4 bytes</ENTRY> <entry>4 bytes</entry>
<ENTRY>Variable-precision</ENTRY> <entry>Variable-precision</entry>
<ENTRY>6 decimal places</ENTRY> <entry>6 decimal places</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>float8</ENTRY> <entry>float8</entry>
<ENTRY>8 bytes</ENTRY> <entry>8 bytes</entry>
<ENTRY>Variable-precision</ENTRY> <entry>Variable-precision</entry>
<ENTRY>15 decimal places</ENTRY> <entry>15 decimal places</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>int2</ENTRY> <entry>int2</entry>
<ENTRY>2 bytes</ENTRY> <entry>2 bytes</entry>
<ENTRY>Fixed-precision</ENTRY> <entry>Fixed-precision</entry>
<ENTRY>-32768 to +32767</ENTRY> <entry>-32768 to +32767</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>int4</ENTRY> <entry>int4</entry>
<ENTRY>4 bytes</ENTRY> <entry>4 bytes</entry>
<ENTRY>Usual choice for fixed-precision</ENTRY> <entry>Usual choice for fixed-precision</entry>
<ENTRY>-2147483648 to +2147483647</ENTRY> <entry>-2147483648 to +2147483647</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>int8</ENTRY> <entry>int8</entry>
<ENTRY>8 bytes</ENTRY> <entry>8 bytes</entry>
<ENTRY>Very large range fixed-precision</ENTRY> <entry>Very large range fixed-precision</entry>
<ENTRY>+/- &gt; 18 decimal places</ENTRY> <entry>+/- &gt; 18 decimal places</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>serial</ENTRY> <entry>serial</entry>
<ENTRY>4 bytes</ENTRY> <entry>4 bytes</entry>
<ENTRY>Identifer or cross-reference</ENTRY> <entry>Identifer or cross-reference</entry>
<ENTRY>0 to +2147483647</ENTRY> <entry>0 to +2147483647</entry>
</ROW> </row>
</TBODY> </tbody>
</TGROUP> </tgroup>
</TABLE> </table>
</Para> </para>
<para> <para>
The numeric types have a full set of corresponding arithmetic operators and The numeric types have a full set of corresponding arithmetic operators and
functions. Refer to <xref linkend="math-opers" endterm="math-opers"> functions. Refer to <xref endterm="math-opers" linkend="math-opers">
and <xref linkend="math-funcs" endterm="math-funcs"> for more information. and <xref endterm="math-funcs" linkend="math-funcs"> for more information.
</para>
<para> <para>
The <type>serial</type> type is a special-case type constructed by The <type>serial</type> type is a special-case type constructed by
...@@ -358,325 +360,327 @@ CREATE TABLE <replaceable class="parameter">tablename</replaceable> (<replaceabl ...@@ -358,325 +360,327 @@ CREATE TABLE <replaceable class="parameter">tablename</replaceable> (<replaceabl
</programlisting> </programlisting>
The sequence will remain in the database until explicitly dropped using The sequence will remain in the database until explicitly dropped using
<command>DROP SEQUENCE</command>. <command>DROP SEQUENCE</command>.</para>
</caution> </caution>
</para>
<Para> <para>
The <FirstTerm>exact numerics</FirstTerm> <Type>decimal</Type> and The <firstterm>exact numerics</firstterm> <type>decimal</type> and
<Type>numeric</Type> <type>numeric</type>
have fully implemented syntax but currently have fully implemented syntax but currently
(<ProductName>Postgres</ProductName> v6.4) (<productname>Postgres</productname> v6.4)
support only a small range of precision and/or range values. support only a small range of precision and/or range values.
The <type>int8</type> type may not be available on all platforms since The <type>int8</type> type may not be available on all platforms since
it relies on compiler support for this. it relies on compiler support for this.
</Para> </para>
</Sect1> </sect1>
<Sect1> <sect1>
<Title>Monetary Type</Title> <title>Monetary Type</title>
<Para> <para>
The <Type>money</Type> type supports US-style currency with The <type>money</type> type supports US-style currency with
fixed decimal point representation. fixed decimal point representation.
If <ProductName>Postgres</ProductName> is compiled with USE_LOCALE If <productname>Postgres</productname> is compiled with USE_LOCALE
then the money type then the money type should use the monetary conventions defined for
should use the monetary conventions defined for <citetitle>locale(7)</citetitle>.
<citetitle>locale(7)</citetitle>. </para>
<Para> <para>
<TABLE TOCENTRY="1"> <table tocentry="1">
<TITLE><ProductName>Postgres</ProductName> Monetary Types</TITLE> <title><productname>Postgres</productname> Monetary Types</title>
<TITLEABBREV>Money</TITLEABBREV> <titleabbrev>Money</titleabbrev>
<TGROUP COLS="4"> <tgroup cols="4">
<THEAD> <thead>
<ROW> <row>
<ENTRY>Monetary Type</ENTRY> <entry>Monetary Type</entry>
<ENTRY>Storage</ENTRY> <entry>Storage</entry>
<ENTRY>Description</ENTRY> <entry>Description</entry>
<ENTRY>Range</ENTRY> <entry>Range</entry>
</ROW> </row>
</THEAD> </thead>
<TBODY> <tbody>
<ROW> <row>
<ENTRY>money</ENTRY> <entry>money</entry>
<ENTRY>4 bytes</ENTRY> <entry>4 bytes</entry>
<ENTRY>Fixed-precision</ENTRY> <entry>Fixed-precision</entry>
<ENTRY>-21474836.48 to +21474836.47</ENTRY> <entry>-21474836.48 to +21474836.47</entry>
</ROW> </row>
</TBODY> </tbody>
</TGROUP> </tgroup>
</TABLE> </table>
</Para> </para>
<Para> <para>
<type>numeric</type> <type>numeric</type>
should eventually replace the money type. It has a should eventually replace the money type. It has a
fully implemented syntax but currently fully implemented syntax but currently
(<ProductName>Postgres</ProductName> v6.4) (<productname>Postgres</productname> v6.4)
support only a small range of precision and/or range values support only a small range of precision and/or range values
and cannot adequately substitute for the money type. and cannot adequately substitute for the money type.
</Para> </para>
</Sect1> </sect1>
<Sect1> <sect1>
<Title>Character Types</Title> <title>Character Types</title>
<Para> <para>
<Acronym>SQL92</Acronym> defines two primary character types: <acronym>SQL92</acronym> defines two primary character types:
<Type>char</Type> and <Type>varchar</Type>. <type>char</type> and <type>varchar</type>.
<ProductName>Postgres</ProductName> supports these types, in <productname>Postgres</productname> supports these types, in
addition to the more general <Type>text</Type> type, addition to the more general <type>text</type> type,
which unlike <Type>varchar</Type> which unlike <type>varchar</type>
does not require an upper does not require an upper
limit to be declared on the size of the field. limit to be declared on the size of the field.
</Para> </para>
<Para> <para>
<TABLE TOCENTRY="1"> <table tocentry="1">
<TITLE><ProductName>Postgres</ProductName> Character Types</TITLE> <title><productname>Postgres</productname> Character Types</title>
<TITLEABBREV>Characters</TITLEABBREV> <titleabbrev>Characters</titleabbrev>
<TGROUP COLS="4"> <tgroup cols="4">
<THEAD> <thead>
<ROW> <row>
<ENTRY>Character Type</ENTRY> <entry>Character Type</entry>
<ENTRY>Storage</ENTRY> <entry>Storage</entry>
<ENTRY>Recommendation</ENTRY> <entry>Recommendation</entry>
<ENTRY>Description</ENTRY> <entry>Description</entry>
</ROW> </row>
</THEAD> </thead>
<TBODY> <tbody>
<ROW> <row>
<ENTRY>char</ENTRY> <entry>char</entry>
<ENTRY>1 byte</ENTRY> <entry>1 byte</entry>
<ENTRY><acronym>SQL92</acronym>-compatible</ENTRY> <entry><acronym>SQL92</acronym>-compatible</entry>
<ENTRY>Single character</ENTRY> <entry>Single character</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>char(n)</ENTRY> <entry>char(n)</entry>
<ENTRY>(4+n) bytes</ENTRY> <entry>(4+n) bytes</entry>
<ENTRY><acronym>SQL92</acronym>-compatible</ENTRY> <entry><acronym>SQL92</acronym>-compatible</entry>
<ENTRY>Fixed-length blank padded</ENTRY> <entry>Fixed-length blank padded</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>text</ENTRY> <entry>text</entry>
<ENTRY>(4+x) bytes</ENTRY> <entry>(4+x) bytes</entry>
<ENTRY>Best choice</ENTRY> <entry>Best choice</entry>
<ENTRY>Variable-length</ENTRY> <entry>Variable-length</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>varchar(n)</ENTRY> <entry>varchar(n)</entry>
<ENTRY>(4+n) bytes</ENTRY> <entry>(4+n) bytes</entry>
<ENTRY><acronym>SQL92</acronym>-compatible</ENTRY> <entry><acronym>SQL92</acronym>-compatible</entry>
<ENTRY>Variable-length with limit</ENTRY> <entry>Variable-length with limit</entry>
</ROW> </row>
</TBODY> </tbody>
</TGROUP> </tgroup>
</TABLE> </table>
</Para> </para>
<Para> <para>
There is one other fixed-length character type. There is one other fixed-length character type.
The <Type>name</Type> type The <type>name</type> type
only has one purpose and that is to provide only has one purpose and that is to provide
<ProductName>Postgres</ProductName> with a <productname>Postgres</productname> with a
special type to use for internal names. special type to use for internal names.
It is not intended for use by the general user. It is not intended for use by the general user.
It's length is currently defined as 32 chars It's length is currently defined as 32 chars
but should be reference using NAMEDATALEN. but should be reference using NAMEDATALEN.
This is set at compile time and may change in a future release. This is set at compile time and may change in a future release.
</Para> </para>
<Para> <para>
<TABLE TOCENTRY="1"> <table tocentry="1">
<TITLE><ProductName>Postgres</ProductName> Specialty Character Type</TITLE> <title><productname>Postgres</productname> Specialty Character Type</title>
<TITLEABBREV>Specialty Characters</TITLEABBREV> <titleabbrev>Specialty Characters</titleabbrev>
<TGROUP COLS="3"> <tgroup cols="3">
<THEAD> <thead>
<ROW> <row>
<ENTRY>Character Type</ENTRY> <entry>Character Type</entry>
<ENTRY>Storage</ENTRY> <entry>Storage</entry>
<ENTRY>Description</ENTRY> <entry>Description</entry>
</ROW> </row>
</THEAD> </thead>
<TBODY> <tbody>
<ROW> <row>
<ENTRY>name</ENTRY> <entry>name</entry>
<ENTRY>32 bytes</ENTRY> <entry>32 bytes</entry>
<ENTRY>Thirty-two character internal type</ENTRY> <entry>Thirty-two character internal type</entry>
</ROW> </row>
</TBODY> </tbody>
</TGROUP> </tgroup>
</TABLE> </table>
</Para> </para>
</Sect1> </sect1>
<Sect1> <sect1>
<Title>Date/Time Types</Title> <title>Date/Time Types</title>
<Para> <para>
There are two fundamental kinds of date and time measurements: There are two fundamental kinds of date and time measurements:
absolute clock times and relative time intervals. absolute clock times and relative time intervals.
Both quantities should demonstrate continuity and smoothness, as does time itself. Both kinds of quantities should have behaviors demonstrating both
<ProductName>Postgres</ProductName> supplies two primary user-oriented continuity and smoothness.
<productname>Postgres</productname> supplies two primary user-oriented
date and time types, date and time types,
<Type>datetime</Type> and <Type>timespan</Type>, as well as <type>datetime</type> and <type>timespan</type>, as well as
the related <acronym>SQL92</acronym> types <Type>timestamp</Type>, the related <acronym>SQL92</acronym> types <type>timestamp</type>,
<Type>interval</Type>, <type>interval</type>,
<Type>date</Type> and <Type>time</Type>. <type>date</type> and <type>time</type>.
</Para> </para>
<Para> <para>
In a future release, <Type>datetime</Type> and <Type>timespan</Type> are likely In a future release, <type>datetime</type> and <type>timespan</type> are likely
to merge with the <acronym>SQL92</acronym> types <Type>timestamp</Type>, to merge with the <acronym>SQL92</acronym> types <type>timestamp</type>,
<Type>interval</Type>. <type>interval</type>.
Other date and time types are also available, mostly Other date and time types are also available, mostly
for historical reasons. for historical reasons.
</Para> </para>
<Para> <para>
<TABLE TOCENTRY="1"> <table tocentry="1">
<TITLE><ProductName>Postgres</ProductName> Date/Time Types</TITLE> <title><productname>Postgres</productname> Date/Time Types</title>
<TITLEABBREV>Date/Time</TITLEABBREV> <titleabbrev>Date/Time</titleabbrev>
<TGROUP COLS="4"> <tgroup cols="4">
<THEAD> <thead>
<ROW> <row>
<ENTRY>Date/Time Type</ENTRY> <entry>Date/Time Type</entry>
<ENTRY>Storage</ENTRY> <entry>Storage</entry>
<ENTRY>Recommendation</ENTRY> <entry>Recommendation</entry>
<ENTRY>Description</ENTRY> <entry>Description</entry>
</ROW> </row>
</THEAD> </thead>
<TBODY> <tbody>
<ROW> <row>
<ENTRY>abstime</ENTRY> <entry>abstime</entry>
<ENTRY>4 bytes</ENTRY> <entry>4 bytes</entry>
<ENTRY>original date and time</ENTRY> <entry>original date and time</entry>
<ENTRY>limited range</ENTRY> <entry>limited range</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>date</ENTRY> <entry>date</entry>
<ENTRY>4 bytes</ENTRY> <entry>4 bytes</entry>
<ENTRY><acronym>SQL92</acronym> type</ENTRY> <entry><acronym>SQL92</acronym> type</entry>
<ENTRY>wide range</ENTRY> <entry>wide range</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>datetime</ENTRY> <entry>datetime</entry>
<ENTRY>8 bytes</ENTRY> <entry>8 bytes</entry>
<ENTRY>best general date and time</ENTRY> <entry>best general date and time</entry>
<ENTRY>wide range, high precision</ENTRY> <entry>wide range, high precision</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>interval</ENTRY> <entry>interval</entry>
<ENTRY>12 bytes</ENTRY> <entry>12 bytes</entry>
<ENTRY><acronym>SQL92</acronym> type</ENTRY> <entry><acronym>SQL92</acronym> type</entry>
<ENTRY>equivalent to timespan</ENTRY> <entry>equivalent to timespan</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>reltime</ENTRY> <entry>reltime</entry>
<ENTRY>4 bytes</ENTRY> <entry>4 bytes</entry>
<ENTRY>original time interval</ENTRY> <entry>original time interval</entry>
<ENTRY>limited range, low precision</ENTRY> <entry>limited range, low precision</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>time</ENTRY> <entry>time</entry>
<ENTRY>4 bytes</ENTRY> <entry>4 bytes</entry>
<ENTRY><acronym>SQL92</acronym> type</ENTRY> <entry><acronym>SQL92</acronym> type</entry>
<ENTRY>wide range</ENTRY> <entry>wide range</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>timespan</ENTRY> <entry>timespan</entry>
<ENTRY>12 bytes</ENTRY> <entry>12 bytes</entry>
<ENTRY>best general time interval</ENTRY> <entry>best general time interval</entry>
<ENTRY>wide range, high precision</ENTRY> <entry>wide range, high precision</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>timestamp</ENTRY> <entry>timestamp</entry>
<ENTRY>4 bytes</ENTRY> <entry>4 bytes</entry>
<ENTRY><acronym>SQL92</acronym> type</ENTRY> <entry><acronym>SQL92</acronym> type</entry>
<ENTRY>limited range</ENTRY> <entry>limited range</entry>
</ROW> </row>
</TBODY> </tbody>
</TGROUP> </tgroup>
</TABLE> </table>
<type>timestamp</type> is currently implemented separately from <type>timestamp</type> is currently implemented separately from
<type>datetime</type>, although they share input and output routines. <type>datetime</type>, although they share input and output routines.
</Para> </para>
<Para> <para>
<TABLE TOCENTRY="1"> <table tocentry="1">
<TITLE><ProductName>Postgres</ProductName> Date/Time Ranges</TITLE> <title><productname>Postgres</productname> Date/Time Ranges</title>
<TITLEABBREV>Ranges</TITLEABBREV> <titleabbrev>Ranges</titleabbrev>
<TGROUP COLS="4"> <tgroup cols="4">
<THEAD> <thead>
<ROW> <row>
<ENTRY>Date/Time Type</ENTRY> <entry>Date/Time Type</entry>
<ENTRY>Earliest</ENTRY> <entry>Earliest</entry>
<ENTRY>Latest</ENTRY> <entry>Latest</entry>
<ENTRY>Resolution</ENTRY> <entry>Resolution</entry>
</ROW> </row>
</THEAD> </thead>
<TBODY> <tbody>
<ROW> <row>
<ENTRY>abstime</ENTRY> <entry>abstime</entry>
<ENTRY>1901-12-14</ENTRY> <entry>1901-12-14</entry>
<ENTRY>2038-01-19</ENTRY> <entry>2038-01-19</entry>
<ENTRY>1 sec</ENTRY> <entry>1 sec</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>date</ENTRY> <entry>date</entry>
<ENTRY>4713 BC</ENTRY> <entry>4713 BC</entry>
<ENTRY>32767 AD</ENTRY> <entry>32767 AD</entry>
<ENTRY>1 day</ENTRY> <entry>1 day</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>datetime</ENTRY> <entry>datetime</entry>
<ENTRY>4713 BC</ENTRY> <entry>4713 BC</entry>
<ENTRY>1465001 AD</ENTRY> <entry>1465001 AD</entry>
<ENTRY>1 microsec to 14 digits</ENTRY> <entry>1 microsec to 14 digits</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>interval</ENTRY> <entry>interval</entry>
<ENTRY>-178000000 years</ENTRY> <entry>-178000000 years</entry>
<ENTRY>178000000 years</ENTRY> <entry>178000000 years</entry>
<ENTRY>1 microsec</ENTRY> <entry>1 microsec</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>reltime</ENTRY> <entry>reltime</entry>
<ENTRY>-68 years</ENTRY> <entry>-68 years</entry>
<ENTRY>+68 years</ENTRY> <entry>+68 years</entry>
<ENTRY>1 sec</ENTRY> <entry>1 sec</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>time</ENTRY> <entry>time</entry>
<ENTRY>00:00:00.00</ENTRY> <entry>00:00:00.00</entry>
<ENTRY>23:59:59.99</ENTRY> <entry>23:59:59.99</entry>
<ENTRY>1 microsec</ENTRY> <entry>1 microsec</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>timespan</ENTRY> <entry>timespan</entry>
<ENTRY>-178000000 years</ENTRY> <entry>-178000000 years</entry>
<ENTRY>178000000 years</ENTRY> <entry>178000000 years</entry>
<ENTRY>1 microsec (14 digits)</ENTRY> <entry>1 microsec (14 digits)</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>timestamp</ENTRY> <entry>timestamp</entry>
<ENTRY>1901-12-14</ENTRY> <entry>1901-12-14</entry>
<ENTRY>2038-01-19</ENTRY> <entry>2038-01-19</entry>
<ENTRY>1 sec</ENTRY> <entry>1 sec</entry>
</ROW> </row>
</TBODY> </tbody>
</TGROUP> </tgroup>
</TABLE> </table>
</Para> </para>
<Para> <para>
<ProductName>Postgres</ProductName> endevours to be compatible with <productname>Postgres</productname> endeavors to be compatible with
<Acronym>SQL92</Acronym> definitions for typical usage. <acronym>SQL92</acronym> definitions for typical usage.
The <Acronym>SQL92</Acronym> standard has an odd mix of date and The <acronym>SQL92</acronym> standard has an odd mix of date and
time types and capabilities. Two obvious problems are: time types and capabilities. Two obvious problems are:
<itemizedlist> <itemizedlist>
...@@ -684,12 +688,12 @@ time types and capabilities. Two obvious problems are: ...@@ -684,12 +688,12 @@ time types and capabilities. Two obvious problems are:
<para> <para>
Although the <type>date</type> type Although the <type>date</type> type
does not have an associated time zone, the does not have an associated time zone, the
<type>time</type> type can or does. <type>time</type> type can or does.</para></listitem>
<listitem> <listitem>
<para> <para>
The default time zone is specified as a constant integer offset The default time zone is specified as a constant integer offset
from GMT/UTC. from GMT/UTC.</para></listitem>
</itemizedlist> </itemizedlist>
...@@ -697,9 +701,10 @@ However, time zones in the real world can have no meaning unless ...@@ -697,9 +701,10 @@ However, time zones in the real world can have no meaning unless
associated with a date as well as a time associated with a date as well as a time
since the offset may vary through the year with daylight savings since the offset may vary through the year with daylight savings
time boundaries. time boundaries.
</para>
<Para> <para>
To address these difficulties, <ProductName>Postgres</ProductName> To address these difficulties, <productname>Postgres</productname>
associates time zones only with date and time associates time zones only with date and time
types which contain both date and time, types which contain both date and time,
and assumes local time for any type containing only and assumes local time for any type containing only
...@@ -707,291 +712,296 @@ date or time. Further, time zone support is derived from ...@@ -707,291 +712,296 @@ date or time. Further, time zone support is derived from
the underlying operating system the underlying operating system
time zone capabilities, and hence can handle daylight savings time time zone capabilities, and hence can handle daylight savings time
and other expected behavior. and other expected behavior.
</para>
<Para> <para>
In future releases, the number of date/time types will decrease, In future releases, the number of date/time types will decrease,
with the current implementation of with the current implementation of
<Type>datetime</Type> becoming <Type>timestamp</Type>, <type>datetime</type> becoming <type>timestamp</type>,
<Type>timespan</Type> becoming <Type>interval</Type>, <type>timespan</type> becoming <type>interval</type>,
and (possibly) <Type>abstime</Type> and <Type>reltime</Type> and (possibly) <type>abstime</type> and <type>reltime</type>
being deprecated in favor of <Type>timestamp</Type> and <Type>interval</Type>. being deprecated in favor of <type>timestamp</type> and <type>interval</type>.
The more arcane features of the date/time definitions from The more arcane features of the date/time definitions from
the <Acronym>SQL92</Acronym> standard are not likely to be pursued. the <acronym>SQL92</acronym> standard are not likely to be pursued.
</Para> </para>
<Sect2> <sect2>
<Title>Date/Time Styles</Title> <title>Date/Time Styles</title>
<Para> <para>
Output formats can be set to one of four styles: Output formats can be set to one of four styles:
ISO-8601, <acronym>SQL</acronym> (Ingres), traditional ISO-8601, <acronym>SQL</acronym> (Ingres), traditional
Postgres, and German. Postgres, and German.
<TABLE TOCENTRY="1"> <table tocentry="1">
<TITLE><ProductName>Postgres</ProductName> Date Styles</TITLE> <title><productname>Postgres</productname> Date Styles</title>
<TITLEABBREV>Styles</TITLEABBREV> <titleabbrev>Styles</titleabbrev>
<TGROUP COLS="3"> <tgroup cols="3">
<THEAD> <thead>
<ROW> <row>
<ENTRY>Style Specification</ENTRY> <entry>Style Specification</entry>
<ENTRY>Description</ENTRY> <entry>Description</entry>
<ENTRY>Example</ENTRY> <entry>Example</entry>
</ROW> </row>
</THEAD> </thead>
<TBODY> <tbody>
<ROW> <row>
<ENTRY>ISO</ENTRY> <entry>ISO</entry>
<ENTRY>ISO-8601 standard</ENTRY> <entry>ISO-8601 standard</entry>
<ENTRY>1997-12-17 07:37:16-08</ENTRY> <entry>1997-12-17 07:37:16-08</entry>
</ROW> </row>
<ROW> <row>
<ENTRY><acronym>SQL</acronym></ENTRY> <entry><acronym>SQL</acronym></entry>
<ENTRY>Traditional style</ENTRY> <entry>Traditional style</entry>
<ENTRY>12/17/1997 07:37:16.00 PST</ENTRY> <entry>12/17/1997 07:37:16.00 PST</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>Postgres</ENTRY> <entry>Postgres</entry>
<ENTRY>Original style</ENTRY> <entry>Original style</entry>
<ENTRY>Wed Dec 17 07:37:16 1997 PST</ENTRY> <entry>Wed Dec 17 07:37:16 1997 PST</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>German</ENTRY> <entry>German</entry>
<ENTRY>Regional style</ENTRY> <entry>Regional style</entry>
<ENTRY>17.12.1997 07:37:16.00 PST</ENTRY> <entry>17.12.1997 07:37:16.00 PST</entry>
</ROW> </row>
</TBODY> </tbody>
</TGROUP> </tgroup>
</TABLE> </table>
</Para> </para>
<Para> <para>
The <acronym>SQL</acronym> style has European and non-European (US) variants, The <acronym>SQL</acronym> style has European and non-European (US) variants,
which determines whether month follows day or vica versa. which determines whether month follows day or vica versa.
<TABLE TOCENTRY="1"> <table tocentry="1">
<TITLE><ProductName>Postgres</ProductName> Date Order Conventions</TITLE> <title><productname>Postgres</productname> Date Order Conventions</title>
<TITLEABBREV>Order</TITLEABBREV> <titleabbrev>Order</titleabbrev>
<TGROUP COLS="3"> <tgroup cols="3">
<THEAD> <thead>
<ROW> <row>
<ENTRY>Style Specification</ENTRY> <entry>Style Specification</entry>
<ENTRY>Description</ENTRY> <entry>Description</entry>
<ENTRY>Example</ENTRY> <entry>Example</entry>
</ROW> </row>
</THEAD> </thead>
<TBODY> <tbody>
<ROW> <row>
<ENTRY>European</ENTRY> <entry>European</entry>
<ENTRY>Regional convention</ENTRY> <entry>Regional convention</entry>
<ENTRY>17/12/1997 15:37:16.00 MET</ENTRY> <entry>17/12/1997 15:37:16.00 MET</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>NonEuropean</ENTRY> <entry>NonEuropean</entry>
<ENTRY>Regional convention</ENTRY> <entry>Regional convention</entry>
<ENTRY>12/17/1997 07:37:16.00 PST</ENTRY> <entry>12/17/1997 07:37:16.00 PST</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>US</ENTRY> <entry>US</entry>
<ENTRY>Regional convention</ENTRY> <entry>Regional convention</entry>
<ENTRY>12/17/1997 07:37:16.00 PST</ENTRY> <entry>12/17/1997 07:37:16.00 PST</entry>
</ROW> </row>
</TBODY> </tbody>
</TGROUP> </tgroup>
</TABLE> </table>
</Para> </para>
<Para> <para>
There are several ways to affect the appearance of date/time types: There are several ways to affect the appearance of date/time types:
<ItemizedList Mark="bullet" Spacing="compact"> <itemizedlist spacing="compact" mark="bullet">
<ListItem> <listitem>
<Para> <para>
The PGDATESTYLE environment variable used by the backend directly The PGDATESTYLE environment variable used by the backend directly
on postmaster startup. on postmaster startup.
</Para> </para>
</ListItem> </listitem>
<ListItem> <listitem>
<Para> <para>
The PGDATESTYLE environment variable used by the frontend libpq The PGDATESTYLE environment variable used by the frontend libpq
on session startup. on session startup.
</Para> </para>
</ListItem> </listitem>
<ListItem> <listitem>
<Para> <para>
SET DateStyle <Acronym>SQL</Acronym> command. <command>SET DATESTYLE</command> <acronym>SQL</acronym> command.
</Para> </para>
</ListItem> </listitem>
</ItemizedList> </itemizedlist>
</para>
<Para>
For <ProductName>Postgres</ProductName> v6.4 (and earlier) <para>
For <productname>Postgres</productname> v6.4 (and earlier)
the default date/time style is the default date/time style is
"non-European traditional Postgres". "non-European traditional Postgres".
In future releases, the default may become ISO-8601, which alleviates In future releases, the default may become "ISO" (compatible with ISO-8601),
date specification ambiguities and Y2K collation problems. which alleviates date specification ambiguities and Y2K collation problems.
</Para> </para>
</Sect2> </sect2>
<Sect2> <sect2>
<Title>Time Zones</Title> <title>Time Zones</title>
<Para> <para>
<ProductName>Postgres</ProductName> obtains time zone support <productname>Postgres</productname> obtains time zone support
from the underlying operating system. from the underlying operating system.
All dates and times are stored internally in Universal Coordinated Time (UTC), All dates and times are stored internally in Universal Coordinated Time (UTC),
alternately known as Greenwich Mean Time (GMT). alternately known as Greenwich Mean Time (GMT).
Times are converted to local time on the database server before being Times are converted to local time on the database server before being
sent to the client frontend, hence by default are in the server time zone. sent to the client frontend, hence by default are in the server time zone.</para>
<Para> <para>
There are several ways to affect the time zone behavior: There are several ways to affect the time zone behavior:
<ItemizedList Mark="bullet" Spacing="compact"> <itemizedlist spacing="compact" mark="bullet">
<ListItem> <listitem>
<Para> <para>
The TZ environment variable used by the backend directly The TZ environment variable used by the backend directly
on postmaster startup as the default time zone. on postmaster startup as the default time zone.
</Para> </para>
</ListItem> </listitem>
<ListItem> <listitem>
<Para> <para>
The PGTZ environment variable set at the client used by libpq The PGTZ environment variable set at the client used by libpq
to send time zone information to the backend upon connection. to send time zone information to the backend upon connection.
</Para> </para>
</ListItem> </listitem>
<ListItem> <listitem>
<Para> <para>
The <Acronym>SQL</Acronym> command <Command>SET TIME ZONE</Command> The <acronym>SQL</acronym> command <command>SET TIME ZONE</command>
sets the time zone for the session. sets the time zone for the session.
</Para> </para>
</ListItem> </listitem>
</ItemizedList> </itemizedlist></para>
<Para> <para>
If an invalid time zone is specified, If an invalid time zone is specified,
the time zone becomes GMT (on most systems anyway). the time zone becomes GMT (on most systems anyway).
</Para> </para>
</Sect2> </sect2>
<Sect2> <sect2>
<Title>Date/Time Input</Title> <title>Date/Time Input</title>
<Para> <para>
General-use date and time is input using a wide range of General-use date and time is input using a wide range of
styles, including ISO-compatible, <acronym>SQL</acronym>-compatible, styles, including ISO-compatible, <acronym>SQL</acronym>-compatible,
traditional <ProductName>Postgres</ProductName> traditional <productname>Postgres</productname>
and other permutations of date and time. In cases where interpretation and other permutations of date and time. In cases where interpretation
can be ambiguous (quite possible with many traditional styles of date can be ambiguous (quite possible with many traditional styles of date
specification) <ProductName>Postgres</ProductName> uses a style setting specification) <productname>Postgres</productname> uses a style setting
to resolve the ambiguity. to resolve the ambiguity.
</Para> </para>
<Para> <para>
Most date and time types share code for data input. For those types Most date and time types share code for data input. For those types
the input can have any of a wide variety of styles. For numeric date the input can have any of a wide variety of styles. For numeric date
representations, representations,
European and US conventions can differ, and the proper interpretation European and US conventions can differ, and the proper interpretation
is obtained is obtained by using the <command>SET DATESTYLE</command>
by using the
<Command>set datestyle</Command>
command before entering data. command before entering data.
Note that the style setting does not preclude use of various styles for input; Note that the style setting does not preclude use of various styles for input;
it is it is used primarily to determine the output style and to resolve ambiguities.
used primarily to determine the output style and to resolve ambiguities. </para>
</Para>
<para>
<Para> The special values <literal>current</literal>,
The special values `current', <literal>infinity</literal> and <literal>-infinity</literal> are provided.
`infinity' and `-infinity' are provided. <literal>infinity</literal> specifies a time later than any other valid time, and
`infinity' specifies a time later than any other valid time, and <literal>-infinity</literal> specifies a time earlier than any other valid time.
`-infinity' specifies a time earlier than any other valid time. <literal>current</literal> indicates that the current time should be
`current' indicates that the current time should be substituted whenever this value appears in a computation.
substituted whenever this value appears in a computation. </para>
The strings <para>
`now', The strings
`today', <literal>now</literal>,
`yesterday', <literal>today</literal>,
`tomorrow', <literal>yesterday</literal>,
and `epoch' can be used to specify <literal>tomorrow</literal>,
time values. `now' means the current transaction time, and differs from and <literal>epoch</literal>
`current' in that the current time is immediately substituted can be used to specify
for it. `epoch' means Jan 1 00:00:00 1970 GMT. time values. <literal>now</literal>
</Para> means the current transaction time, and differs from
<literal>current</literal>
<Para> in that the current time is immediately substituted
<TABLE TOCENTRY="1"> for it. <literal>epoch</literal>
<TITLE><ProductName>Postgres</ProductName> Date/Time Special Constants</TITLE> means Jan 1 00:00:00 1970 GMT.
<TITLEABBREV>Constants</TITLEABBREV> </para>
<TGROUP COLS="2">
<THEAD> <para>
<ROW> <table tocentry="1">
<ENTRY>Constant</ENTRY> <title><productname>Postgres</productname> Date/Time Special Constants</title>
<ENTRY>Description</ENTRY> <titleabbrev>Constants</titleabbrev>
</ROW> <tgroup cols="2">
</THEAD> <thead>
<TBODY> <row>
<ROW> <entry>Constant</entry>
<ENTRY>current</ENTRY> <entry>Description</entry>
<ENTRY>Current transaction time, deferred</ENTRY> </row>
</ROW> </thead>
<ROW> <tbody>
<ENTRY>epoch</ENTRY> <row>
<ENTRY>1970-01-01 00:00:00+00 (Unix system time zero)</ENTRY> <entry>current</entry>
</ROW> <entry>Current transaction time, deferred</entry>
<ROW> </row>
<ENTRY>infinity</ENTRY> <row>
<ENTRY>Later than other valid times</ENTRY> <entry>epoch</entry>
</ROW> <entry>1970-01-01 00:00:00+00 (Unix system time zero)</entry>
<ROW> </row>
<ENTRY>-infinity</ENTRY> <row>
<ENTRY>Earlier than other valid times</ENTRY> <entry>infinity</entry>
</ROW> <entry>Later than other valid times</entry>
<ROW> </row>
<ENTRY>invalid</ENTRY> <row>
<ENTRY>Illegal entry</ENTRY> <entry>-infinity</entry>
</ROW> <entry>Earlier than other valid times</entry>
<ROW> </row>
<ENTRY>now</ENTRY> <row>
<ENTRY>Current transaction time</ENTRY> <entry>invalid</entry>
</ROW> <entry>Illegal entry</entry>
<ROW> </row>
<ENTRY>today</ENTRY> <row>
<ENTRY>Midnight today</ENTRY> <entry>now</entry>
</ROW> <entry>Current transaction time</entry>
<ROW> </row>
<ENTRY>tomorrow</ENTRY> <row>
<ENTRY>Midnight tomorrow</ENTRY> <entry>today</entry>
</ROW> <entry>Midnight today</entry>
<ROW> </row>
<ENTRY>yesterday</ENTRY> <row>
<ENTRY>Midnight yesterday</ENTRY> <entry>tomorrow</entry>
</ROW> <entry>Midnight tomorrow</entry>
</TBODY> </row>
</TGROUP> <row>
</TABLE> <entry>yesterday</entry>
</Para> <entry>Midnight yesterday</entry>
</row>
</Sect2> </tbody>
</tgroup>
<Sect2> </table>
<Title>datetime</Title> </para>
<Para> </sect2>
<sect2>
<title>datetime</title>
<para>
General-use date and time is input using a wide range of General-use date and time is input using a wide range of
styles, including ISO-compatible, <acronym>SQL</acronym>-compatible, traditional styles, including ISO-compatible, <acronym>SQL</acronym>-compatible, traditional
<ProductName>Postgres</ProductName> (see section on "absolute time") <productname>Postgres</productname> (see section on "absolute time")
and other permutations of date and time. Output styles can be ISO-compatible, and other permutations of date and time. Output styles can be ISO-compatible,
<acronym>SQL</acronym>-compatible, or traditional <acronym>SQL</acronym>-compatible, or traditional
<ProductName>Postgres</ProductName>, with the default set to be compatible <productname>Postgres</productname>, with the default set to be compatible
with <ProductName>Postgres</ProductName> v6.0. with <productname>Postgres</productname> v6.0.
</Para> </para>
<Para> <para>
<Type>datetime</Type> is specified using the following syntax: <type>datetime</type> is specified using the following syntax:
<ProgramListing> <programlisting>
Year-Month-Day [ Hour : Minute : Second ] [AD,BC] [ Timezone ] Year-Month-Day [ Hour : Minute : Second ] [AD,BC] [ Timezone ]
YearMonthDay [ Hour : Minute : Second ] [AD,BC] [ Timezone ] YearMonthDay [ Hour : Minute : Second ] [AD,BC] [ Timezone ]
Month Day [ Hour : Minute : Second ] Year [AD,BC] [ Timezone ] Month Day [ Hour : Minute : Second ] Year [AD,BC] [ Timezone ]
...@@ -1003,62 +1013,65 @@ where ...@@ -1003,62 +1013,65 @@ where
Minute is 00, 01, ..., 59 Minute is 00, 01, ..., 59
Second is 00, 01, ..., 59 (60 for leap second) Second is 00, 01, ..., 59 (60 for leap second)
Timezone is 3 characters or ISO offset to GMT Timezone is 3 characters or ISO offset to GMT
</ProgramListing> </programlisting>
</para>
<Para> <para>
Valid dates are from Nov 13 00:00:00 4013 BC GMT to far into the future. Valid dates are from Nov 13 00:00:00 4013 BC GMT to far into the future.
Timezones are either three characters (e.g. "GMT" or "PST") or ISO-compatible Timezones are either three characters (e.g. "GMT" or "PST") or ISO-compatible
offsets to GMT (e.g. "-08" or "-08:00" when in Pacific Standard Time). offsets to GMT (e.g. "-08" or "-08:00" when in Pacific Standard Time).
Dates are stored internally in Greenwich Mean Time. Input and output routines Dates are stored internally in Greenwich Mean Time. Input and output routines
translate time to the local time zone of the server. translate time to the local time zone of the server.
</Para> </para></sect2>
<Sect2> <sect2>
<Title><Type>timespan</Type></Title> <title><type>timespan</type></title>
<Para> <para>
General-use time span is input using a wide range of General-use time span is input using a wide range of
syntaxes, including ISO-compatible, <acronym>SQL</acronym>-compatible, syntaxes, including ISO-compatible, <acronym>SQL</acronym>-compatible,
traditional traditional
<ProductName>Postgres</ProductName> (see section on "relative time") <productname>Postgres</productname> (see section on "relative time")
and other permutations of time span. Output formats can be ISO-compatible, and other permutations of time span. Output formats can be ISO-compatible,
<acronym>SQL</acronym>-compatible, or traditional <acronym>SQL</acronym>-compatible, or traditional
<ProductName>Postgres</ProductName>, <productname>Postgres</productname>,
with the default set to be <ProductName>Postgres</ProductName>-compatible. with the default set to be <productname>Postgres</productname>-compatible.
Months and years are a "qualitative" time interval, and are stored separately Months and years are a "qualitative" time interval, and are stored separately
from the other "quantitative" time intervals such as day or hour. from the other "quantitative" time intervals such as day or hour.
For date arithmetic, For date arithmetic,
the qualitative time units are instantiated in the context of the the qualitative time units are instantiated in the context of the
relevant date or time. relevant date or time.
</para>
<Para> <para>
Time span is specified with the following syntax: Time span is specified with the following syntax:
<ProgramListing> <programlisting>
Quantity Unit [Quantity Unit...] [Direction] Quantity Unit [Quantity Unit...] [Direction]
@ Quantity Unit [Direction] @ Quantity Unit [Direction]
where where
Quantity is ..., `-1', `0', `1', `2', ... Quantity is ..., <literal>-1</literal>, <literal>0</literal>, <literal>1</literal>, <literal>2</literal>, ...
Unit is `second', `minute', `hour', `day', `week', `month', `year', Unit is <literal>second</literal>, <literal>minute</literal>, <literal>hour</literal>, <literal>day</literal>, <literal>week</literal>, <literal>month</literal>, <literal>year</literal>,
'decade', 'century', millenium', or abbreviations or plurals of these units. <literal>decade</literal>, <literal>century</literal>, <literal>millenium</literal>, or abbreviations or plurals of these units.
Direction is `ago'. Direction is <literal>ago</literal>.
</ProgramListing> </programlisting>
</Para> </para>
</Sect2> </sect2>
<Sect2> <sect2>
<Title>abstime</Title> <title>abstime</title>
<Para> <para>
Absolute time (<type>abstime</type>) is a limited-range (+/- 68 years) and Absolute time (<type>abstime</type>) is a limited-range (+/- 68 years) and
limited-precision (1 sec) limited-precision (1 sec)
date data type. <Type>datetime</Type> may be preferred, since it date data type. <type>datetime</type> may be preferred, since it
covers a larger range with greater precision. covers a larger range with greater precision.
</para>
<Para>
<para>
Absolute time is specified using the following syntax: Absolute time is specified using the following syntax:
<ProgramListing> <programlisting>
Month Day [ Hour : Minute : Second ] Year [ Timezone ] Month Day [ Hour : Minute : Second ] Year [ Timezone ]
where where
Month is Jan, Feb, ..., Dec Month is Jan, Feb, ..., Dec
...@@ -1067,311 +1080,315 @@ where ...@@ -1067,311 +1080,315 @@ where
Minute is 00, 01, ..., 59 Minute is 00, 01, ..., 59
Second is 00, 01, ..., 59 Second is 00, 01, ..., 59
Year is 1901, 1902, ..., 2038 Year is 1901, 1902, ..., 2038
</ProgramListing> </programlisting>
</Para> </para>
<Para> <para>
Valid dates are from Dec 13 20:45:53 1901 GMT to Jan 19 03:14:04 Valid dates are from <literal>Dec 13 20:45:53 1901 GMT</literal>
2038 GMT. to <literal>Jan 19 03:14:04 2038 GMT</literal>.
<note> <note>
<title>Historical Note</title> <title>Historical Note</title>
<para> <para>
As of Version 3.0, times are no longer read and written As of Version 3.0, times are no longer read and written
using Greenwich Mean Time; the input and output routines default to using Greenwich Mean Time; the input and output routines default to
the local time zone. the local time zone.</para>
</note> </note>
All special values allowed for <Type>datetime</Type> are also All special values allowed for <type>datetime</type> are also
allowed for "absolute time". allowed for "absolute time".
</Para> </para>
</Sect2> </sect2>
<Sect2> <sect2>
<Title>reltime</Title> <title>reltime</title>
<Para> <para>
Relative time <Type>reltime</Type> is a limited-range (+/- 68 years) Relative time <type>reltime</type> is a limited-range (+/- 68 years)
and limited-precision (1 sec) time span data type. and limited-precision (1 sec) time span data type.
<Type>timespan</Type> should be preferred, since it <type>timespan</type> should be preferred, since it
covers a larger range with greater precision and, more importantly, covers a larger range with greater precision and, more importantly,
can distinguish between can distinguish between
relative units (months and years) and quantitative units (days, hours, etc). relative units (months and years) and quantitative units (days, hours, etc).
Instead, reltime Instead, reltime
must force months to be exactly 30 days, so time arithmetic does not must force months to be exactly 30 days, so time arithmetic does not
always work as expected. always work as expected.
For example, adding one reltime year to abstime today does not For example, adding one reltime <literal>year</literal> to abstime <literal>today</literal> does not
produce today's date one year from produce today's date one year from
now, but rather a date 360 days from today. now, but rather a date 360 days from today.
</Para> </para>
<Para> <para>
<Type>reltime</Type> shares input and output routines with the other <type>reltime</type> shares input and output routines with the other
time span types. time span types.
The section on <Type>timespan</Type> covers this in more detail. The section on <type>timespan</type> covers this in more detail.
</Para> </para>
</Sect2> </sect2>
<Sect2> <sect2>
<Title><Type>timestamp</Type></Title> <title><type>timestamp</type></title>
<Para> <para>
This is currently a limited-range absolute time which closely resembles the This is currently a limited-range absolute time which closely resembles the
abstime abstime
data type. It shares the general input parser with the other date/time types. data type. It shares the general input parser with the other date/time types.
In future releases this type will absorb the capabilities of the In future releases this type will absorb the capabilities of the
<Type>datetime</Type> type <type>datetime</type> type
and will move toward <acronym>SQL92</acronym> compliance. and will move toward <acronym>SQL92</acronym> compliance.
</Para> </para>
<Para> <para>
<Type>timestamp</Type> is specified using the same syntax as for <type>timestamp</type> is specified using the same syntax as for
<Type>datetime</Type>. <type>datetime</type>.
</Para> </para>
</Sect2> </sect2>
<Sect2> <sect2>
<Title><Type>interval</Type></Title> <title><type>interval</type></title>
<Para> <para>
<Type>interval</Type> is an <Acronym>SQL92</Acronym> data type which is <type>interval</type> is an <acronym>SQL92</acronym> data type which is
currently mapped to the <Type>timespan</Type> currently mapped to the <type>timespan</type>
<ProductName>Postgres</ProductName> data type. <productname>Postgres</productname> data type.
</Para> </para>
</Sect2> </sect2>
<Sect2> <sect2>
<Title>tinterval</Title> <title>tinterval</title>
<Para> <para>
Time ranges are specified as: Time ranges are specified as:
<ProgramListing> <programlisting>
[ 'abstime' 'abstime'] [ 'abstime' 'abstime']
where where
abstime is a time in the absolute time format. abstime is a time in the absolute time format.
</ProgramListing> </programlisting>
Special abstime values such as Special abstime values such as
`current', `infinity' and `-infinity' can be used. <literal>current', <literal>infinity' and <literal>-infinity' can be used.</literal></literal></literal>
</Para> </para></sect2>
</Sect1> </sect1>
<Sect1> <sect1>
<Title>Boolean Type</Title> <title>Boolean Type</title>
<Para> <para>
<ProductName>Postgres</ProductName> supports <Type>bool</Type> as <productname>Postgres</productname> supports <type>bool</type> as
the <Acronym>SQL3</Acronym> boolean type. the <acronym>SQL3</acronym> boolean type.
<Type>bool</Type> can have one of only two states: 'true' or 'false'. <type>bool</type> can have one of only two states: 'true' or 'false'.
A third state, 'unknown', is not A third state, 'unknown', is not
implemented and is not suggested in <Acronym>SQL3</Acronym>; implemented and is not suggested in <acronym>SQL3</acronym>;
<Acronym>NULL</Acronym> is an <acronym>NULL</acronym> is an
effective substitute. <Type>bool</Type> can be used in any boolean expression, effective substitute. <type>bool</type> can be used in any boolean expression,
and boolean expressions and boolean expressions
always evaluate to a result compatible with this type. always evaluate to a result compatible with this type.</para>
<Para> <para>
<Type>bool</Type> uses 4 bytes of storage. <type>bool</type> uses 4 bytes of storage.
</Para> </para>
<Para> <para>
<TABLE TOCENTRY="1"> <table tocentry="1">
<TITLE><ProductName>Postgres</ProductName> Boolean Type</TITLE> <title><productname>Postgres</productname> Boolean Type</title>
<TITLEABBREV>Booleans</TITLEABBREV> <titleabbrev>Booleans</titleabbrev>
<TGROUP COLS="3"> <tgroup cols="3">
<THEAD> <thead>
<ROW> <row>
<ENTRY>State</ENTRY> <entry>State</entry>
<ENTRY>Output</ENTRY> <entry>Output</entry>
<ENTRY>Input</ENTRY> <entry>Input</entry>
</ROW> </row>
</THEAD> </thead>
<TBODY> <tbody>
<ROW> <row>
<ENTRY>True</ENTRY> <entry>True</entry>
<ENTRY>'t'</ENTRY> <entry>'t'</entry>
<ENTRY>TRUE, 't', 'true', 'y', 'yes', '1'</ENTRY> <entry>TRUE, 't', 'true', 'y', 'yes', '1'</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>False</ENTRY> <entry>False</entry>
<ENTRY>'f'</ENTRY> <entry>'f'</entry>
<ENTRY>FALSE, 'f', 'false', 'n', 'no', '0'</ENTRY> <entry>FALSE, 'f', 'false', 'n', 'no', '0'</entry>
</ROW> </row>
</TBODY> </tbody>
</TGROUP> </tgroup>
</TABLE> </table>
</Para> </para>
</Sect1> </sect1>
<Sect1> <sect1>
<Title>Geometric Types</Title> <title>Geometric Types</title>
<Para> <para>
Geometric types represent two-dimensional spatial objects. Geometric types represent two-dimensional spatial objects.
The most fundamental type, The most fundamental type,
the point, forms the basis for all of the other types. the point, forms the basis for all of the other types.
</Para> </para>
<Para> <para>
<TABLE TOCENTRY="1"> <table tocentry="1">
<TITLE><ProductName>Postgres</ProductName> Geometric Types</TITLE> <title><productname>Postgres</productname> Geometric Types</title>
<TITLEABBREV>Geometrics</TITLEABBREV> <titleabbrev>Geometrics</titleabbrev>
<TGROUP COLS="4"> <tgroup cols="4">
<THEAD> <thead>
<ROW> <row>
<ENTRY>Geometric Type</ENTRY> <entry>Geometric Type</entry>
<ENTRY>Storage</ENTRY> <entry>Storage</entry>
<ENTRY>Representation</ENTRY> <entry>Representation</entry>
<ENTRY>Description</ENTRY> <entry>Description</entry>
</ROW> </row>
</THEAD> </thead>
<TBODY> <tbody>
<ROW> <row>
<ENTRY>point</ENTRY> <entry>point</entry>
<ENTRY>16 bytes</ENTRY> <entry>16 bytes</entry>
<ENTRY>(x,y)</ENTRY> <entry>(x,y)</entry>
<ENTRY>Point in space</ENTRY> <entry>Point in space</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>line</ENTRY> <entry>line</entry>
<ENTRY>32 bytes</ENTRY> <entry>32 bytes</entry>
<ENTRY>((x1,y1),(x2,y2))</ENTRY> <entry>((x1,y1),(x2,y2))</entry>
<ENTRY>Infinite line</ENTRY> <entry>Infinite line</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>lseg</ENTRY> <entry>lseg</entry>
<ENTRY>32 bytes</ENTRY> <entry>32 bytes</entry>
<ENTRY>((x1,y1),(x2,y2))</ENTRY> <entry>((x1,y1),(x2,y2))</entry>
<ENTRY>Finite line segment</ENTRY> <entry>Finite line segment</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>box</ENTRY> <entry>box</entry>
<ENTRY>32 bytes</ENTRY> <entry>32 bytes</entry>
<ENTRY>((x1,y1),(x2,y2))</ENTRY> <entry>((x1,y1),(x2,y2))</entry>
<ENTRY>Rectangular box</ENTRY> <entry>Rectangular box</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>path</ENTRY> <entry>path</entry>
<ENTRY>4+32n bytes</ENTRY> <entry>4+32n bytes</entry>
<ENTRY>((x1,y1),...)</ENTRY> <entry>((x1,y1),...)</entry>
<ENTRY>Closed path (similar to polygon)</ENTRY> <entry>Closed path (similar to polygon)</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>path</ENTRY> <entry>path</entry>
<ENTRY>4+32n bytes</ENTRY> <entry>4+32n bytes</entry>
<ENTRY>[(x1,y1),...]</ENTRY> <entry>[(x1,y1),...]</entry>
<ENTRY>Open path</ENTRY> <entry>Open path</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>polygon</ENTRY> <entry>polygon</entry>
<ENTRY>4+32n bytes</ENTRY> <entry>4+32n bytes</entry>
<ENTRY>((x1,y1),...)</ENTRY> <entry>((x1,y1),...)</entry>
<ENTRY>Polygon (similar to closed path)</ENTRY> <entry>Polygon (similar to closed path)</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>circle</ENTRY> <entry>circle</entry>
<ENTRY>24 bytes</ENTRY> <entry>24 bytes</entry>
<ENTRY><(x,y),r></ENTRY> <entry><(x,y),r></entry>
<ENTRY>Circle (center and radius)</ENTRY> <entry>Circle (center and radius)</entry>
</ROW> </row>
</TBODY> </tbody>
</TGROUP> </tgroup>
</TABLE> </table>
</Para> </para>
<Para> <para>
A rich set of functions and operators is available to perform various geometric A rich set of functions and operators is available to perform various geometric
operations such as scaling, translation, rotation, and determining operations such as scaling, translation, rotation, and determining
intersections. intersections.
</Para> </para>
<Sect2> <sect2>
<Title>Point</Title> <title>Point</title>
<Para> <para>
Points are specified using the following syntax: Points are the fundamental two-dimensional building block for geometric types.
</para>
<para>
<type>point</type> is specified using the following syntax:
<ProgramListing> <programlisting>
( x , y ) ( x , y )
x , y x , y
where where
x is the x-axis coordinate as a floating point number x is the x-axis coordinate as a floating point number
y is the y-axis coordinate as a floating point number y is the y-axis coordinate as a floating point number
</ProgramListing> </programlisting>
</Para> </para>
</Sect2> </sect2>
<Sect2> <sect2>
<Title>Line Segment</Title> <title>Line Segment</title>
<Para> <para>
Line segments (lseg) are represented by pairs of points. Line segments (lseg) are represented by pairs of points.
</Para> </para>
<Para> <para>
lseg is specified using the following syntax: <type>lseg</type> is specified using the following syntax:
<ProgramListing> <programlisting>
( ( x1 , y1 ) , ( x2 , y2 ) ) ( ( x1 , y1 ) , ( x2 , y2 ) )
( x1 , y1 ) , ( x2 , y2 ) ( x1 , y1 ) , ( x2 , y2 )
x1 , y1 , x2 , y2 x1 , y1 , x2 , y2
where where
(x1,y1) and (x2,y2) are the endpoints of the segment (x1,y1) and (x2,y2) are the endpoints of the segment
</ProgramListing> </programlisting>
</Para> </para>
</Sect2> </sect2>
<Sect2> <sect2>
<Title>Box</Title> <title>Box</title>
<Para> <para>
Boxes are represented by pairs of points which are opposite Boxes are represented by pairs of points which are opposite
corners of the box. corners of the box.
</Para> </para>
<Para> <para>
box is specified using the following syntax: <type>box</type> is specified using the following syntax:
<ProgramListing> <programlisting>
( ( x1 , y1 ) , ( x2 , y2 ) ) ( ( x1 , y1 ) , ( x2 , y2 ) )
( x1 , y1 ) , ( x2 , y2 ) ( x1 , y1 ) , ( x2 , y2 )
x1 , y1 , x2 , y2 x1 , y1 , x2 , y2
where where
(x1,y1) and (x2,y2) are opposite corners (x1,y1) and (x2,y2) are opposite corners
</ProgramListing> </programlisting>
Boxes are output using the first syntax. Boxes are output using the first syntax.
The corners are reordered on input to store The corners are reordered on input to store
the lower left corner first and the upper right corner last. the lower left corner first and the upper right corner last.
Other corners of the box can be entered, but the lower Other corners of the box can be entered, but the lower
left and upper right corners are determined from the input and stored. left and upper right corners are determined from the input and stored.
</Para> </para>
</Sect2> </sect2>
<Sect2> <sect2>
<Title>Path</Title> <title>Path</title>
<Para> <para>
Paths are represented by connected sets of points. Paths can be "open", where Paths are represented by connected sets of points. Paths can be "open", where
the first and last points in the set are not connected, and "closed", the first and last points in the set are not connected, and "closed",
where the first and last point are connected. Functions where the first and last point are connected. Functions
<Function>popen(p)</Function> <function>popen(p)</function>
and and
<Function>pclose(p)</Function> <function>pclose(p)</function>
are supplied to force a path to be open or closed, and functions are supplied to force a path to be open or closed, and functions
<Function>isopen(p)</Function> <function>isopen(p)</function>
and and
<Function>isclosed(p)</Function> <function>isclosed(p)</function>
are supplied to select either type in a query. are supplied to select either type in a query.
</Para> </para>
<Para> <para>
path is specified using the following syntax: path is specified using the following syntax:
<ProgramListing> <programlisting>
( ( x1 , y1 ) , ... , ( xn , yn ) ) ( ( x1 , y1 ) , ... , ( xn , yn ) )
[ ( x1 , y1 ) , ... , ( xn , yn ) ] [ ( x1 , y1 ) , ... , ( xn , yn ) ]
( x1 , y1 ) , ... , ( xn , yn ) ( x1 , y1 ) , ... , ( xn , yn )
...@@ -1381,60 +1398,60 @@ where ...@@ -1381,60 +1398,60 @@ where
(x1,y1),...,(xn,yn) are points 1 through n (x1,y1),...,(xn,yn) are points 1 through n
a leading "[" indicates an open path a leading "[" indicates an open path
a leading "(" indicates a closed path a leading "(" indicates a closed path
</ProgramListing> </programlisting>
Paths are output using the first syntax. Paths are output using the first syntax.
Note that <ProductName>Postgres</ProductName> versions prior to Note that <productname>Postgres</productname> versions prior to
v6.1 used a format for paths which had a single leading parenthesis, v6.1 used a format for paths which had a single leading parenthesis,
a "closed" flag, a "closed" flag,
an integer count of the number of points, then the list of points followed by a an integer count of the number of points, then the list of points followed by a
closing parenthesis. closing parenthesis.
The built-in function <Function>upgradepath</Function> is supplied to convert The built-in function <function>upgradepath</function> is supplied to convert
paths dumped and reloaded from pre-v6.1 databases. paths dumped and reloaded from pre-v6.1 databases.
</Para> </para>
</Sect2> </sect2>
<Sect2> <sect2>
<Title>Polygon</Title> <title>Polygon</title>
<Para> <para>
Polygons are represented by sets of points. Polygons should probably be Polygons are represented by sets of points. Polygons should probably be
considered equivalent to closed paths, but are stored differently considered equivalent to closed paths, but are stored differently
and have their own set of support routines. and have their own set of support routines.
</Para> </para>
<Para> <para>
polygon is specified using the following syntax: <type>polygon</type> is specified using the following syntax:
<ProgramListing> <programlisting>
( ( x1 , y1 ) , ... , ( xn , yn ) ) ( ( x1 , y1 ) , ... , ( xn , yn ) )
( x1 , y1 ) , ... , ( xn , yn ) ( x1 , y1 ) , ... , ( xn , yn )
( x1 , y1 , ... , xn , yn ) ( x1 , y1 , ... , xn , yn )
x1 , y1 , ... , xn , yn x1 , y1 , ... , xn , yn
where where
(x1,y1),...,(xn,yn) are points 1 through n (x1,y1),...,(xn,yn) are points 1 through n
</ProgramListing> </programlisting>
Polygons are output using the first syntax. Polygons are output using the first syntax.
Note that <ProductName>Postgres</ProductName> versions prior to Note that <productname>Postgres</productname> versions prior to
v6.1 used a format for polygons which had a single leading parenthesis, the list v6.1 used a format for polygons which had a single leading parenthesis, the list
of x-axis coordinates, the list of y-axis coordinates, of x-axis coordinates, the list of y-axis coordinates,
followed by a closing parenthesis. followed by a closing parenthesis.
The built-in function <Function>upgradepoly</Function> is supplied to convert The built-in function <function>upgradepoly</function> is supplied to convert
polygons dumped and reloaded from pre-v6.1 databases. polygons dumped and reloaded from pre-v6.1 databases.
</Para> </para>
</Sect2> </sect2>
<Sect2> <sect2>
<Title>Circle</Title> <title>Circle</title>
<Para> <para>
Circles are represented by a center point and a radius. Circles are represented by a center point and a radius.
</Para> </para>
<Para> <para>
circle is specified using the following syntax: circle is specified using the following syntax:
<ProgramListing> <programlisting>
< ( x , y ) , r > < ( x , y ) , r >
( ( x , y ) , r ) ( ( x , y ) , r )
( x , y ) , r ( x , y ) , r
...@@ -1442,132 +1459,162 @@ circle is specified using the following syntax: ...@@ -1442,132 +1459,162 @@ circle is specified using the following syntax:
where where
(x,y) is the center of the circle (x,y) is the center of the circle
r is the radius of the circle r is the radius of the circle
</ProgramListing> </programlisting>
Circles are output using the first syntax. Circles are output using the first syntax.
</Para> </para>
</Sect2> </sect2>
</Sect1> </sect1>
<Sect1> <sect1>
<Title>IP Version 4 Networks and Host Addresses</Title> <title>IP Version 4 Networks and Host Addresses</title>
<Para> <para>
The <Type>cidr</Type> type stores networks specified The <type>cidr</type> type stores networks specified
in <acronym>CIDR</acronym> notation. in <acronym>CIDR</acronym> (Classless Inter-Domain Routing) notation.
The <Type>inet</Type> type stores hosts and networks in CIDR notation. The <type>inet</type> type stores hosts and networks in CIDR notation using a simple
</Para> variation in representation to represent simple host TCP/IP addresses.
</para>
<Para>
<TABLE TOCENTRY="1"> <para>
<TITLE><ProductName>Postgres</ProductName>IP Version 4 Types</TITLE> <table tocentry="1">
<TITLEABBREV>IPV4</TITLEABBREV> <title><productname>Postgres</productname>IP Version 4 Types</title>
<TGROUP COLS="4"> <titleabbrev>IPV4</titleabbrev>
<THEAD> <tgroup cols="4">
<ROW> <thead>
<ENTRY>IPV4 Type</ENTRY> <row>
<ENTRY>Storage</ENTRY> <entry>IPV4 Type</entry>
<ENTRY>Description</ENTRY> <entry>Storage</entry>
<ENTRY>Range</ENTRY> <entry>Description</entry>
</ROW> <entry>Range</entry>
</THEAD> </row>
<TBODY> </thead>
<ROW> <tbody>
<ENTRY>cidr</ENTRY> <row>
<ENTRY>variable</ENTRY> <entry>cidr</entry>
<ENTRY>CIDR networks</ENTRY> <entry>variable</entry>
<ENTRY>Valid IPV4 CIDR blocks</ENTRY> <entry>CIDR networks</entry>
</ROW> <entry>Valid IPV4 CIDR blocks</entry>
<ROW> </row>
<ENTRY>inet</ENTRY> <row>
<ENTRY>variable</ENTRY> <entry>inet</entry>
<ENTRY>nets and hosts</ENTRY> <entry>variable</entry>
<ENTRY>Valid IPV4 CIDR blocks</ENTRY> <entry>nets and hosts</entry>
</ROW> <entry>Valid IPV4 CIDR blocks</entry>
</TBODY> </row>
</TGROUP> </tbody>
</TABLE> </tgroup>
</Para> </table>
</para>
<Sect2>
<Title><type>inet</type> for IP Networks</Title> <sect2>
<title>CIDR</title>
<Para>
The cidr type holds a CIDR network. <para>
The format for specifying networks is "x.x.x.x/y" where "x.x.x.x" is the The <type>cidr</type> type holds a CIDR network.
network and "/y" is the number of bits in the netmask. The format for specifying classless networks is <replaceable class="parameter">x.x.x.x/y</replaceable>
If the "/y" part is left off, it is calculated using assumptions from where <replaceable class="parameter">x.x.x.x</replaceable> is the
the old class system except that it is extended to include at least network and <replaceable class="parameter">/y</replaceable> is the number of bits in the netmask.
If <replaceable class="parameter">/y</replaceable> omitted, it is calculated using assumptions from
the older classfull naming system except that it is extended to include at least
all of the octets in the input. all of the octets in the input.
</para>
<para>
Here are some examples: Here are some examples:
<Para> <table tocentry="1">
<TABLE TOCENTRY="1"> <title><productname>Postgres</productname>IP Types Examples</title>
<TITLE><ProductName>Postgres</ProductName>IP Types Examples</TITLE> <tgroup cols="2">
<TGROUP COLS="2"> <thead>
<THEAD> <row>
<ROW> <entry>CIDR Input</entry>
<ENTRY>CIDR Input</ENTRY> <entry>CIDR Displayed</entry>
<ENTRY>CIDR Displayed</ENTRY> </row>
</THEAD> </thead>
<TBODY> <tbody>
<ROW> <row>
<ENTRY>192.168.1</ENTRY> <entry>192.168.1</entry>
<ENTRY>192.168.1/24</ENTRY> <entry>192.168.1/24</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>192.168</ENTRY> <entry>192.168</entry>
<ENTRY>192.168.0/24</ENTRY> <entry>192.168.0/24</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>128.1</ENTRY> <entry>128.1</entry>
<ENTRY>128.1/16</ENTRY> <entry>128.1/16</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>128</ENTRY> <entry>128</entry>
<ENTRY>128.0/16</ENTRY> <entry>128.0/16</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>128.1.2</ENTRY> <entry>128.1.2</entry>
<ENTRY>128.1.2/24</ENTRY> <entry>128.1.2/24</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>10.1.2</ENTRY> <entry>10.1.2</entry>
<ENTRY>10.1.2/24</ENTRY> <entry>10.1.2/24</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>10.1</ENTRY> <entry>10.1</entry>
<ENTRY>10.1/16</ENTRY> <entry>10.1/16</entry>
</ROW> </row>
<ROW> <row>
<ENTRY>10</ENTRY> <entry>10</entry>
<ENTRY>10/8</ENTRY> <entry>10/8</entry>
</ROW> </row>
</TBODY> </tbody>
</TGROUP> </tgroup>
</TABLE> </table>
</Para> </para>
</sect2>
<Sect2>
<Title><type>inet</type> for IP Networks</Title> <sect2>
<title id="inet-type"><type>inet</type></title>
<Para>
The inet type is designed to hold, in one field, all of the information <para>
about a host including the CIDR style subnet that it is in. The <type>inet</type> type is designed to hold, in one field, all of the information
Note that if you want to store proper CIDR networks, see the cidr type. about a host including the CIDR-style subnet that it is in.
The inet type is similar to the cidr type except that the bits in the Note that if you want to store proper CIDR networks,
you should use the <type>cidr</type> type.
The <type>inet</type> type is similar to the <type>cidr</type> type except that the bits in the
host part can be non-zero. host part can be non-zero.
Functions exist to extract the various elements of the field. Functions exist to extract the various elements of the field.
</Para> </para>
<Para> <para>
The input format for this function is "x.x.x.x/y" where "x.x.x.x" is The input format for this function is
an internet host and y is the number of bits in the netmask. <replaceable class="parameter">x.x.x.x/y</replaceable>
If the "/y" part is left off, it is treated as "/32." where <replaceable class="parameter">x.x.x.x</replaceable> is
On output, the "/y" part is not printed if it is /32. an internet host and <replaceable class="parameter">y</replaceable>
This allows the type to be used as a straight host type by just leaving of is the number of bits in the netmask.
If the <replaceable class="parameter">/y</replaceable> part is left off,
it is treated as <literal>/32</literal>.
On output, the <replaceable class="parameter">/y</replaceable> part is not printed
if it is <literal>/32</literal>.
This allows the type to be used as a straight host type by just leaving off
the bits part. the bits part.
</Sect1> </para></sect2>
</sect1>
</chapter>
\ No newline at end of file </chapter>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"./reference.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:"/usr/lib/sgml/catalog"
sgml-local-ecat-files:nil
End:
-->
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment