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