2000-03-31 05:27:42 +02:00
|
|
|
<!--
|
2001-10-09 20:46:00 +02:00
|
|
|
$Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.66 2001/10/09 18:45:59 petere Exp $
|
2000-03-31 05:27:42 +02:00
|
|
|
-->
|
|
|
|
|
1999-05-12 09:32:47 +02:00
|
|
|
<chapter id="datatype">
|
1999-06-14 09:36:12 +02:00
|
|
|
<title id="datatype-title">Data Types</title>
|
1998-03-01 09:16:16 +01:00
|
|
|
|
2001-05-13 00:51:36 +02:00
|
|
|
<indexterm zone="datatype">
|
|
|
|
<primary>data types</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
|
|
|
<indexterm>
|
|
|
|
<primary>types</primary>
|
|
|
|
<see>data types</see>
|
|
|
|
</indexterm>
|
|
|
|
|
1999-05-12 09:32:47 +02:00
|
|
|
<para>
|
|
|
|
<productname>Postgres</productname> has a rich set of native data
|
|
|
|
types available to users.
|
|
|
|
Users may add new types to <productname>Postgres</productname> using the
|
2000-04-13 23:44:25 +02:00
|
|
|
<command>CREATE TYPE</command> command.
|
1999-05-12 09:32:47 +02:00
|
|
|
</para>
|
1998-03-01 09:16:16 +01:00
|
|
|
|
1999-05-12 09:32:47 +02:00
|
|
|
<para>
|
2001-01-13 19:34:51 +01:00
|
|
|
<xref linkend="datatype-table"> shows all general-purpose data types
|
|
|
|
available to users. Most of the alternative names listed in the
|
|
|
|
<quote>Aliases</quote> column are the names used internally by
|
|
|
|
<productname>Postgres</productname> for historical reasons. In
|
|
|
|
addition, some internally used or deprecated types are available,
|
|
|
|
but they are not documented here. Many of the built-in types have
|
|
|
|
obvious external formats. However, several types are either unique
|
|
|
|
to <productname>Postgres</productname>, such as open and closed
|
|
|
|
paths, or have several possibilities for formats, such as the date
|
|
|
|
and time types.
|
1999-05-12 09:32:47 +02:00
|
|
|
</para>
|
1998-12-18 17:11:12 +01:00
|
|
|
|
1999-05-12 09:32:47 +02:00
|
|
|
<para>
|
2001-01-13 19:34:51 +01:00
|
|
|
<table id="datatype-table">
|
2001-02-14 20:37:26 +01:00
|
|
|
<title>Data Types</title>
|
1999-05-12 09:32:47 +02:00
|
|
|
<tgroup cols="3">
|
|
|
|
<thead>
|
|
|
|
<row>
|
2001-01-13 19:34:51 +01:00
|
|
|
<entry>Type Name</entry>
|
|
|
|
<entry>Aliases</entry>
|
1999-05-12 09:32:47 +02:00
|
|
|
<entry>Description</entry>
|
|
|
|
</row>
|
|
|
|
</thead>
|
2001-01-13 19:34:51 +01:00
|
|
|
|
1999-05-12 09:32:47 +02:00
|
|
|
<tbody>
|
|
|
|
<row>
|
2001-01-13 19:34:51 +01:00
|
|
|
<entry><type>bigint</type></entry>
|
|
|
|
<entry><type>int8</type></entry>
|
|
|
|
<entry>signed eight-byte integer</entry>
|
1999-05-12 09:32:47 +02:00
|
|
|
</row>
|
2001-01-13 19:34:51 +01:00
|
|
|
|
2001-08-24 22:03:45 +02:00
|
|
|
<row>
|
|
|
|
<entry><type>bigserial</type></entry>
|
|
|
|
<entry><type>serial8</type></entry>
|
|
|
|
<entry>autoincrementing eight-byte integer</entry>
|
|
|
|
</row>
|
|
|
|
|
1999-05-12 09:32:47 +02:00
|
|
|
<row>
|
2001-01-13 19:34:51 +01:00
|
|
|
<entry><type>bit</type></entry>
|
1999-05-12 09:32:47 +02:00
|
|
|
<entry></entry>
|
2001-01-13 19:34:51 +01:00
|
|
|
<entry>fixed-length bit string</entry>
|
1999-05-12 09:32:47 +02:00
|
|
|
</row>
|
2001-01-13 19:34:51 +01:00
|
|
|
|
1999-05-12 09:32:47 +02:00
|
|
|
<row>
|
2001-01-13 19:34:51 +01:00
|
|
|
<entry><type>bit varying(<replaceable>n</replaceable>)</type></entry>
|
|
|
|
<entry><type>varbit(<replaceable>n</replaceable>)</type></entry>
|
|
|
|
<entry>variable-length bit string</entry>
|
1999-05-12 09:32:47 +02:00
|
|
|
</row>
|
2001-01-13 19:34:51 +01:00
|
|
|
|
1999-05-12 09:32:47 +02:00
|
|
|
<row>
|
2001-01-13 19:34:51 +01:00
|
|
|
<entry><type>boolean</type></entry>
|
|
|
|
<entry><type>bool</type></entry>
|
2001-02-14 20:37:26 +01:00
|
|
|
<entry>logical Boolean (true/false)</entry>
|
1999-05-12 09:32:47 +02:00
|
|
|
</row>
|
2001-01-13 19:34:51 +01:00
|
|
|
|
1999-05-12 09:32:47 +02:00
|
|
|
<row>
|
2001-01-13 19:34:51 +01:00
|
|
|
<entry><type>box</type></entry>
|
1999-05-12 09:32:47 +02:00
|
|
|
<entry></entry>
|
2001-01-13 19:34:51 +01:00
|
|
|
<entry>rectangular box in 2D plane</entry>
|
1999-05-12 09:32:47 +02:00
|
|
|
</row>
|
2001-01-13 19:34:51 +01:00
|
|
|
|
2001-09-04 05:17:54 +02:00
|
|
|
<row>
|
|
|
|
<entry><type>bytea</type></entry>
|
|
|
|
<entry></entry>
|
|
|
|
<entry>binary data</entry>
|
|
|
|
</row>
|
|
|
|
|
1999-05-12 09:32:47 +02:00
|
|
|
<row>
|
2001-01-13 19:34:51 +01:00
|
|
|
<entry><type>character(<replaceable>n</replaceable>)</type></entry>
|
|
|
|
<entry><type>char(<replaceable>n</replaceable>)</type></entry>
|
|
|
|
<entry>fixed-length character string</entry>
|
1999-05-12 09:32:47 +02:00
|
|
|
</row>
|
2001-01-13 19:34:51 +01:00
|
|
|
|
1999-10-13 04:44:23 +02:00
|
|
|
<row>
|
2001-01-13 19:34:51 +01:00
|
|
|
<entry><type>character varying(<replaceable>n</replaceable>)</type></entry>
|
|
|
|
<entry><type>varchar(<replaceable>n</replaceable>)</type></entry>
|
|
|
|
<entry>variable-length character string</entry>
|
1999-10-13 04:44:23 +02:00
|
|
|
</row>
|
2001-01-13 19:34:51 +01:00
|
|
|
|
1999-05-12 09:32:47 +02:00
|
|
|
<row>
|
2001-01-13 19:34:51 +01:00
|
|
|
<entry><type>cidr</type></entry>
|
|
|
|
<entry></entry>
|
|
|
|
<entry>IP network address</entry>
|
1999-05-12 09:32:47 +02:00
|
|
|
</row>
|
2001-01-13 19:34:51 +01:00
|
|
|
|
1999-05-12 09:32:47 +02:00
|
|
|
<row>
|
2001-01-13 19:34:51 +01:00
|
|
|
<entry><type>circle</type></entry>
|
|
|
|
<entry></entry>
|
|
|
|
<entry>circle in 2D plane</entry>
|
1999-05-12 09:32:47 +02:00
|
|
|
</row>
|
2001-01-13 19:34:51 +01:00
|
|
|
|
1999-05-12 09:32:47 +02:00
|
|
|
<row>
|
2001-01-13 19:34:51 +01:00
|
|
|
<entry><type>date</type></entry>
|
1999-05-12 09:32:47 +02:00
|
|
|
<entry></entry>
|
2001-01-13 19:34:51 +01:00
|
|
|
<entry>calendar date (year, month, day)</entry>
|
1999-05-12 09:32:47 +02:00
|
|
|
</row>
|
2001-01-13 19:34:51 +01:00
|
|
|
|
1999-05-12 09:32:47 +02:00
|
|
|
<row>
|
2001-01-13 19:34:51 +01:00
|
|
|
<entry><type>double precision</type></entry>
|
|
|
|
<entry><type>float8</type></entry>
|
|
|
|
<entry>double precision floating-point number</entry>
|
1999-05-12 09:32:47 +02:00
|
|
|
</row>
|
2001-01-13 19:34:51 +01:00
|
|
|
|
1999-05-12 09:32:47 +02:00
|
|
|
<row>
|
2001-01-13 19:34:51 +01:00
|
|
|
<entry><type>inet</type></entry>
|
|
|
|
<entry></entry>
|
|
|
|
<entry>IP host address</entry>
|
1999-05-12 09:32:47 +02:00
|
|
|
</row>
|
2001-01-13 19:34:51 +01:00
|
|
|
|
1999-05-12 09:32:47 +02:00
|
|
|
<row>
|
2001-01-13 19:34:51 +01:00
|
|
|
<entry><type>integer</type></entry>
|
|
|
|
<entry><type>int</type>, <type>int4</type></entry>
|
|
|
|
<entry>signed four-byte integer</entry>
|
1999-05-12 09:32:47 +02:00
|
|
|
</row>
|
2001-01-13 19:34:51 +01:00
|
|
|
|
2000-03-14 23:52:53 +01:00
|
|
|
<row>
|
2001-01-13 19:34:51 +01:00
|
|
|
<entry><type>interval</type></entry>
|
|
|
|
<entry></entry>
|
2000-03-14 23:52:53 +01:00
|
|
|
<entry>general-use time span</entry>
|
|
|
|
</row>
|
2001-01-13 19:34:51 +01:00
|
|
|
|
1999-05-12 09:32:47 +02:00
|
|
|
<row>
|
2001-01-13 19:34:51 +01:00
|
|
|
<entry><type>line</type></entry>
|
1999-05-12 09:32:47 +02:00
|
|
|
<entry></entry>
|
|
|
|
<entry>infinite line in 2D plane</entry>
|
|
|
|
</row>
|
2001-01-13 19:34:51 +01:00
|
|
|
|
1999-05-12 09:32:47 +02:00
|
|
|
<row>
|
2001-01-13 19:34:51 +01:00
|
|
|
<entry><type>lseg</type></entry>
|
1999-05-12 09:32:47 +02:00
|
|
|
<entry></entry>
|
|
|
|
<entry>line segment in 2D plane</entry>
|
|
|
|
</row>
|
2001-01-13 19:34:51 +01:00
|
|
|
|
1999-05-12 09:32:47 +02:00
|
|
|
<row>
|
2001-01-13 19:34:51 +01:00
|
|
|
<entry><type>macaddr</type></entry>
|
|
|
|
<entry></entry>
|
|
|
|
<entry>MAC address</entry>
|
1999-05-12 09:32:47 +02:00
|
|
|
</row>
|
2001-01-13 19:34:51 +01:00
|
|
|
|
1999-10-13 04:44:23 +02:00
|
|
|
<row>
|
2001-01-13 19:34:51 +01:00
|
|
|
<entry><type>money</type></entry>
|
|
|
|
<entry></entry>
|
|
|
|
<entry>US-style currency</entry>
|
1999-10-13 04:44:23 +02:00
|
|
|
</row>
|
2001-01-13 19:34:51 +01:00
|
|
|
|
1999-05-12 09:32:47 +02:00
|
|
|
<row>
|
2001-10-09 20:46:00 +02:00
|
|
|
<entry><type>numeric(<replaceable>p</replaceable>, <replaceable>s</replaceable>)</type></entry>
|
|
|
|
<entry><type>decimal(<replaceable>p</replaceable>, <replaceable>s</replaceable>)</type></entry>
|
2001-01-13 19:34:51 +01:00
|
|
|
<entry>exact numeric with selectable precision</entry>
|
1999-05-12 09:32:47 +02:00
|
|
|
</row>
|
2001-01-13 19:34:51 +01:00
|
|
|
|
1999-05-12 09:32:47 +02:00
|
|
|
<row>
|
2001-01-13 19:34:51 +01:00
|
|
|
<entry><type>oid</type></entry>
|
1999-05-12 09:32:47 +02:00
|
|
|
<entry></entry>
|
2001-01-13 19:34:51 +01:00
|
|
|
<entry>object identifier</entry>
|
1999-05-12 09:32:47 +02:00
|
|
|
</row>
|
2001-01-13 19:34:51 +01:00
|
|
|
|
1999-05-12 09:32:47 +02:00
|
|
|
<row>
|
2001-01-13 19:34:51 +01:00
|
|
|
<entry><type>path</type></entry>
|
1999-05-12 09:32:47 +02:00
|
|
|
<entry></entry>
|
2001-01-13 19:34:51 +01:00
|
|
|
<entry>open and closed geometric path in 2D plane</entry>
|
1999-05-12 09:32:47 +02:00
|
|
|
</row>
|
2001-01-13 19:34:51 +01:00
|
|
|
|
1999-05-12 09:32:47 +02:00
|
|
|
<row>
|
2001-01-13 19:34:51 +01:00
|
|
|
<entry><type>point</type></entry>
|
1999-05-12 09:32:47 +02:00
|
|
|
<entry></entry>
|
2001-01-13 19:34:51 +01:00
|
|
|
<entry>geometric point in 2D plane</entry>
|
1999-05-12 09:32:47 +02:00
|
|
|
</row>
|
2001-01-13 19:34:51 +01:00
|
|
|
|
2000-08-25 01:36:29 +02:00
|
|
|
<row>
|
2001-01-13 19:34:51 +01:00
|
|
|
<entry><type>polygon</type></entry>
|
2000-08-25 01:36:29 +02:00
|
|
|
<entry></entry>
|
2001-01-13 19:34:51 +01:00
|
|
|
<entry>closed geometric path in 2D plane</entry>
|
2000-08-25 01:36:29 +02:00
|
|
|
</row>
|
2001-01-13 19:34:51 +01:00
|
|
|
|
1999-05-12 09:32:47 +02:00
|
|
|
<row>
|
2001-01-13 19:34:51 +01:00
|
|
|
<entry><type>real</type></entry>
|
|
|
|
<entry><type>float4</type></entry>
|
|
|
|
<entry>single precision floating-point number</entry>
|
1999-05-12 09:32:47 +02:00
|
|
|
</row>
|
2001-01-13 19:34:51 +01:00
|
|
|
|
1999-05-12 09:32:47 +02:00
|
|
|
<row>
|
2001-01-13 19:34:51 +01:00
|
|
|
<entry><type>smallint</type></entry>
|
|
|
|
<entry><type>int2</type></entry>
|
|
|
|
<entry>signed two-byte integer</entry>
|
1999-05-12 09:32:47 +02:00
|
|
|
</row>
|
2001-01-13 19:34:51 +01:00
|
|
|
|
1999-05-12 09:32:47 +02:00
|
|
|
<row>
|
2001-01-13 19:34:51 +01:00
|
|
|
<entry><type>serial</type></entry>
|
2001-08-16 22:38:56 +02:00
|
|
|
<entry><type>serial4</type></entry>
|
2001-01-13 19:34:51 +01:00
|
|
|
<entry>autoincrementing four-byte integer</entry>
|
1999-05-12 09:32:47 +02:00
|
|
|
</row>
|
2001-01-13 19:34:51 +01:00
|
|
|
|
1999-05-12 09:32:47 +02:00
|
|
|
<row>
|
2001-01-13 19:34:51 +01:00
|
|
|
<entry><type>text</type></entry>
|
|
|
|
<entry></entry>
|
1999-05-12 09:32:47 +02:00
|
|
|
<entry>variable-length character string</entry>
|
|
|
|
</row>
|
1998-12-18 17:11:12 +01:00
|
|
|
|
1999-05-12 09:32:47 +02:00
|
|
|
<row>
|
2001-01-13 19:34:51 +01:00
|
|
|
<entry><type>time [ without time zone ]</type></entry>
|
|
|
|
<entry></entry>
|
|
|
|
<entry>time of day</entry>
|
1999-05-12 09:32:47 +02:00
|
|
|
</row>
|
2001-01-13 19:34:51 +01:00
|
|
|
|
1999-05-12 09:32:47 +02:00
|
|
|
<row>
|
2001-01-13 19:34:51 +01:00
|
|
|
<entry><type>time with time zone</type></entry>
|
2001-09-28 10:15:35 +02:00
|
|
|
<entry>timetz</entry>
|
2001-01-13 19:34:51 +01:00
|
|
|
<entry>time of day, including time zone</entry>
|
1999-05-12 09:32:47 +02:00
|
|
|
</row>
|
2001-01-13 19:34:51 +01:00
|
|
|
|
2001-09-28 10:15:35 +02:00
|
|
|
<row>
|
|
|
|
<entry><type>timestamp without time zone</type></entry>
|
|
|
|
<entry>timestamp</entry>
|
|
|
|
<entry>date and time</entry>
|
|
|
|
</row>
|
|
|
|
|
1999-05-12 09:32:47 +02:00
|
|
|
<row>
|
2001-01-13 19:34:51 +01:00
|
|
|
<entry><type>timestamp [ with time zone ]</type></entry>
|
2001-09-28 10:15:35 +02:00
|
|
|
<entry>timestamptz</entry>
|
2001-01-13 19:34:51 +01:00
|
|
|
<entry>date and time</entry>
|
1999-05-12 09:32:47 +02:00
|
|
|
</row>
|
|
|
|
</tbody>
|
|
|
|
</tgroup>
|
|
|
|
</table>
|
|
|
|
</para>
|
1998-10-27 07:14:41 +01:00
|
|
|
|
2001-01-13 19:34:51 +01:00
|
|
|
<note>
|
|
|
|
<title>Compatibility</title>
|
|
|
|
<para>
|
|
|
|
The following types (or spellings thereof) are specified by SQL:
|
|
|
|
<type>bit</type>, <type>bit varying</type>, <type>boolean</type>,
|
|
|
|
<type>char</type>, <type>character</type>, <type>character
|
|
|
|
varying</type>, <type>varchar</type>, <type>date</type>,
|
|
|
|
<type>double precision</type>, <type>integer</type>,
|
|
|
|
<type>interval</type>, <type>numeric</type>, <type>decimal</type>,
|
|
|
|
<type>real</type>, <type>smallint</type>, <type>time</type>,
|
|
|
|
<type>timestamp</type> (both with or without time zone).
|
|
|
|
</para>
|
|
|
|
</note>
|
1998-03-01 09:16:16 +01:00
|
|
|
|
1999-05-12 09:32:47 +02:00
|
|
|
<para>
|
|
|
|
Most of the input and output functions corresponding to the
|
|
|
|
base types (e.g., integers and floating point numbers) do some
|
|
|
|
error-checking.
|
|
|
|
Some of the operators and functions (e.g.,
|
|
|
|
addition and multiplication) do not perform run-time error-checking in the
|
|
|
|
interests of improving execution speed.
|
|
|
|
On some systems, for example, the numeric operators for some data types may
|
|
|
|
silently underflow or overflow.
|
|
|
|
</para>
|
1998-03-01 09:16:16 +01:00
|
|
|
|
1999-05-12 09:32:47 +02:00
|
|
|
<para>
|
2000-03-14 23:52:53 +01:00
|
|
|
Some of the input and output functions are not invertible. That is,
|
1999-05-12 09:32:47 +02:00
|
|
|
the result of an output function may lose precision when compared to
|
|
|
|
the original input.
|
|
|
|
</para>
|
1998-03-01 09:16:16 +01:00
|
|
|
|
2001-01-13 19:34:51 +01:00
|
|
|
<sect1 id="datatype-numeric">
|
1999-05-12 09:32:47 +02:00
|
|
|
<title>Numeric Types</title>
|
1998-03-01 09:16:16 +01:00
|
|
|
|
2001-05-13 00:51:36 +02:00
|
|
|
<indexterm zone="datatype-numeric">
|
|
|
|
<primary>data types</primary>
|
|
|
|
<secondary>numeric</secondary>
|
|
|
|
</indexterm>
|
|
|
|
|
|
|
|
<indexterm zone="datatype-numeric">
|
|
|
|
<primary>integer</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
|
|
|
<indexterm zone="datatype-numeric">
|
|
|
|
<primary>smallint</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
|
|
|
<indexterm zone="datatype-numeric">
|
|
|
|
<primary>bigint</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
|
|
|
<indexterm>
|
|
|
|
<primary>int4</primary>
|
|
|
|
<see>integer</see>
|
|
|
|
</indexterm>
|
|
|
|
|
|
|
|
<indexterm>
|
|
|
|
<primary>int2</primary>
|
|
|
|
<see>smallint</see>
|
|
|
|
</indexterm>
|
|
|
|
|
|
|
|
<indexterm>
|
|
|
|
<primary>int8</primary>
|
|
|
|
<see>bigint</see>
|
|
|
|
</indexterm>
|
|
|
|
|
|
|
|
<indexterm zone="datatype-numeric">
|
|
|
|
<primary>numeric (data type)</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
|
|
|
<indexterm>
|
|
|
|
<primary>decimal</primary>
|
|
|
|
<see>numeric</see>
|
|
|
|
</indexterm>
|
|
|
|
|
|
|
|
<indexterm zone="datatype-numeric">
|
|
|
|
<primary>real</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
|
|
|
<indexterm zone="datatype-numeric">
|
|
|
|
<primary>double precision</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
|
|
|
<indexterm>
|
|
|
|
<primary>float4</primary>
|
|
|
|
<see>real</see>
|
|
|
|
</indexterm>
|
|
|
|
|
|
|
|
<indexterm>
|
|
|
|
<primary>float8</primary>
|
|
|
|
<see>double precision</see>
|
|
|
|
</indexterm>
|
|
|
|
|
|
|
|
<indexterm zone="datatype-numeric">
|
|
|
|
<primary>floating point</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
1999-05-12 09:32:47 +02:00
|
|
|
<para>
|
2000-08-25 01:36:29 +02:00
|
|
|
Numeric types consist of two-, four-, and eight-byte integers,
|
|
|
|
four- and eight-byte
|
2000-05-02 22:02:03 +02:00
|
|
|
floating point numbers and fixed-precision decimals.
|
1998-12-18 17:11:12 +01:00
|
|
|
</para>
|
1998-10-14 18:26:31 +02:00
|
|
|
|
1999-08-06 15:43:42 +02:00
|
|
|
<para>
|
|
|
|
<table tocentry="1">
|
2001-02-14 20:37:26 +01:00
|
|
|
<title>Numeric Types</title>
|
1999-08-06 15:43:42 +02:00
|
|
|
<tgroup cols="4">
|
|
|
|
<thead>
|
|
|
|
<row>
|
2001-08-24 22:03:45 +02:00
|
|
|
<entry>Type name</entry>
|
|
|
|
<entry>Storage size</entry>
|
1999-08-06 15:43:42 +02:00
|
|
|
<entry>Description</entry>
|
|
|
|
<entry>Range</entry>
|
|
|
|
</row>
|
|
|
|
</thead>
|
2001-01-13 19:34:51 +01:00
|
|
|
|
1999-08-06 15:43:42 +02:00
|
|
|
<tbody>
|
1999-10-13 04:44:23 +02:00
|
|
|
<row>
|
2001-09-09 19:21:59 +02:00
|
|
|
<entry><type>smallint</></entry>
|
1999-08-06 15:43:42 +02:00
|
|
|
<entry>2 bytes</entry>
|
|
|
|
<entry>Fixed-precision</entry>
|
|
|
|
<entry>-32768 to +32767</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
2001-09-09 19:21:59 +02:00
|
|
|
<entry><type>integer</></entry>
|
1999-08-06 15:43:42 +02:00
|
|
|
<entry>4 bytes</entry>
|
|
|
|
<entry>Usual choice for fixed-precision</entry>
|
|
|
|
<entry>-2147483648 to +2147483647</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
2001-09-09 19:21:59 +02:00
|
|
|
<entry><type>bigint</></entry>
|
1999-08-06 15:43:42 +02:00
|
|
|
<entry>8 bytes</entry>
|
|
|
|
<entry>Very large range fixed-precision</entry>
|
2001-08-24 22:03:45 +02:00
|
|
|
<entry>about 18 decimal digits</entry>
|
2001-01-13 19:34:51 +01:00
|
|
|
</row>
|
|
|
|
|
|
|
|
<row>
|
2001-09-09 19:21:59 +02:00
|
|
|
<entry><type>decimal</></entry>
|
2001-01-13 19:34:51 +01:00
|
|
|
<entry>variable</entry>
|
2001-08-24 22:03:45 +02:00
|
|
|
<entry>user-specified precision, exact</entry>
|
2001-01-13 19:34:51 +01:00
|
|
|
<entry>no limit</entry>
|
1999-10-13 04:44:23 +02:00
|
|
|
</row>
|
|
|
|
<row>
|
2001-09-09 19:21:59 +02:00
|
|
|
<entry><type>numeric</></entry>
|
1999-10-13 04:44:23 +02:00
|
|
|
<entry>variable</entry>
|
2001-08-24 22:03:45 +02:00
|
|
|
<entry>user-specified precision, exact</entry>
|
1999-10-13 04:44:23 +02:00
|
|
|
<entry>no limit</entry>
|
1999-08-06 15:43:42 +02:00
|
|
|
</row>
|
2001-01-13 19:34:51 +01:00
|
|
|
|
|
|
|
<row>
|
2001-09-09 19:21:59 +02:00
|
|
|
<entry><type>real</></entry>
|
2001-01-13 19:34:51 +01:00
|
|
|
<entry>4 bytes</entry>
|
2001-08-24 22:03:45 +02:00
|
|
|
<entry>variable-precision, inexact</entry>
|
|
|
|
<entry>6 decimal digits precision</entry>
|
2001-01-13 19:34:51 +01:00
|
|
|
</row>
|
|
|
|
<row>
|
2001-09-09 19:21:59 +02:00
|
|
|
<entry><type>double precision</></entry>
|
2001-01-13 19:34:51 +01:00
|
|
|
<entry>8 bytes</entry>
|
2001-08-24 22:03:45 +02:00
|
|
|
<entry>variable-precision, inexact</entry>
|
|
|
|
<entry>15 decimal digits precision</entry>
|
2001-01-13 19:34:51 +01:00
|
|
|
</row>
|
|
|
|
|
1999-08-06 15:43:42 +02:00
|
|
|
<row>
|
2001-09-09 19:21:59 +02:00
|
|
|
<entry><type>serial</></entry>
|
1999-08-06 15:43:42 +02:00
|
|
|
<entry>4 bytes</entry>
|
2001-08-24 22:03:45 +02:00
|
|
|
<entry>autoincrementing integer</entry>
|
2001-08-16 22:38:56 +02:00
|
|
|
<entry>1 to 2147483647</entry>
|
|
|
|
</row>
|
|
|
|
|
|
|
|
<row>
|
2001-09-09 19:21:59 +02:00
|
|
|
<entry><type>bigserial</type></entry>
|
2001-08-16 22:38:56 +02:00
|
|
|
<entry>8 bytes</entry>
|
2001-08-24 22:03:45 +02:00
|
|
|
<entry>autoincrementing integer</entry>
|
2001-08-16 22:38:56 +02:00
|
|
|
<entry>1 to 9223372036854775807</entry>
|
1999-08-06 15:43:42 +02:00
|
|
|
</row>
|
|
|
|
</tbody>
|
|
|
|
</tgroup>
|
|
|
|
</table>
|
|
|
|
</para>
|
1998-10-14 18:26:31 +02:00
|
|
|
|
1999-08-06 15:43:42 +02:00
|
|
|
<para>
|
2001-01-26 23:04:22 +01:00
|
|
|
The syntax of constants for the numeric types is described in
|
|
|
|
<xref linkend="sql-syntax-constants">. The numeric types have a
|
|
|
|
full set of corresponding arithmetic operators and
|
|
|
|
functions. Refer to <xref linkend="functions"> for more
|
2001-08-24 22:03:45 +02:00
|
|
|
information. The following sections describe the types in detail.
|
1999-08-06 15:43:42 +02:00
|
|
|
</para>
|
|
|
|
|
2001-08-24 22:03:45 +02:00
|
|
|
<sect2 id="datatype-int">
|
|
|
|
<title>The Integer Types</title>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
The types <type>smallint</type>, <type>integer</type>,
|
|
|
|
<type>bigint</type> store whole numbers, that is, numbers without
|
|
|
|
fractional components, of various ranges. Attempts to store
|
|
|
|
values outside of the allowed range will result in an error.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
The type <type>integer</type> is the usual choice, as it offers
|
|
|
|
the best balance between range, storage size, and performance.
|
|
|
|
The <type>smallint</type> type is generally only used if disk
|
|
|
|
space is at a premium. The <type>bigint</type> type should only
|
|
|
|
be used if the <type>integer</type> range is not sufficient,
|
|
|
|
because the latter is definitely faster.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
The <type>bigint</type> type may not function correctly on all
|
|
|
|
platforms, since it relies on compiler support for eight-byte
|
|
|
|
integers. On a machine without such support, <type>bigint</type>
|
|
|
|
acts the same as <type>integer</type> (but still takes up eight
|
|
|
|
bytes of storage). However, we are not aware of any reasonable
|
|
|
|
platform where this is actually the case.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<note>
|
|
|
|
<para>
|
|
|
|
If you have a column of type <type>smallint</type> or
|
|
|
|
<type>bigint</type> with an index, you may encounter problems
|
|
|
|
getting the system to use that index. For instance, a clause of
|
|
|
|
the form
|
|
|
|
<programlisting>
|
|
|
|
... WHERE smallint_column = 42
|
|
|
|
</programlisting>
|
|
|
|
will not use an index, because the system assigns type
|
|
|
|
<type>integer</type> to the 42, and PostgreSQL currently cannot
|
|
|
|
use an index when two different data types are involved. A
|
|
|
|
workaround is to single-quote the constant, thus:
|
|
|
|
<programlisting>
|
|
|
|
... WHERE smallint_column = '42'
|
|
|
|
</programlisting>
|
|
|
|
This will cause the system to delay the type resolution and will
|
|
|
|
assign the right type to the constant.
|
|
|
|
</para>
|
|
|
|
</note>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
SQL only specifies the integer types <type>integer</type> (or
|
|
|
|
<type>int</type>) and <type>smallint</type>. The type
|
|
|
|
<type>bigint</type>, and the type names <type>int2</type>,
|
|
|
|
<type>int4</type>, and <type>int8</type> are extensions, which
|
|
|
|
are shared with various other RDBMS products.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
</sect2>
|
|
|
|
|
|
|
|
<sect2 id="datatype-numeric-decimal">
|
|
|
|
<title>Arbitrary Precision Numbers</title>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
The type <type>numeric</type> can store numbers of practically
|
|
|
|
unlimited size and precision, while being able to store all
|
|
|
|
numbers and carry out all calculations exactly. It is especially
|
|
|
|
recommended for storing monetary amounts and other quantities
|
|
|
|
where exactness is required. However, the <type>numeric</type>
|
|
|
|
type is very slow compared to the floating point types described
|
|
|
|
in the next section.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
In what follows we use these terms: The
|
|
|
|
<firstterm>scale</firstterm> of a <type>numeric</type> is the
|
|
|
|
count of decimal digits in the fractional part, to the right of
|
|
|
|
the decimal point. The <firstterm>precision</firstterm> of a
|
|
|
|
<type>numeric</type> is the total count of significant digits in
|
|
|
|
the whole number, that is, the number of digits to both sides of
|
|
|
|
the decimal point. So the number 23.5141 has a precision of 6
|
|
|
|
and a scale of 4. Integers can be considered to have a scale of
|
|
|
|
zero.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Both the precision and the scale of the numeric type can be
|
|
|
|
configured. To declare a column of type <type>numeric</type> use
|
|
|
|
the syntax
|
|
|
|
<programlisting>
|
|
|
|
NUMERIC(<replaceable>precision</replaceable>, <replaceable>scale</replaceable>)
|
|
|
|
</programlisting>
|
|
|
|
The precision must be positive, the scale zero or positive.
|
|
|
|
Alternatively,
|
|
|
|
<programlisting>
|
|
|
|
NUMERIC(<replaceable>precision</replaceable>)
|
|
|
|
</programlisting>
|
|
|
|
selects a scale of 0. Merely specifying
|
|
|
|
<programlisting>
|
|
|
|
NUMERIC
|
|
|
|
</programlisting>
|
|
|
|
uses a default precision and scale, which is currently (30,6).
|
|
|
|
(The SQL standard requires a default scale of 0. We find this a
|
|
|
|
bit useless. If you're concerned about portability, always
|
|
|
|
specify the precision and scale explicitly.)
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
If the precision or scale of a value is greater than the declared
|
|
|
|
precision or scale of a column, the system will attempt to round
|
|
|
|
the value. If the value cannot be rounded so as to satisfy the
|
|
|
|
declared limits, an error is raised.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
The types <type>decimal</type> and <type>numeric</type> are
|
|
|
|
equivalent. Both types are part of the SQL standard.
|
|
|
|
</para>
|
|
|
|
</sect2>
|
|
|
|
|
|
|
|
|
|
|
|
<sect2 id="datatype-float">
|
|
|
|
<title>Floating Point Types</title>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
The data types <type>real</type> and <type>double
|
|
|
|
precision</type> are inexact, variable precision numeric types.
|
2001-09-09 19:21:59 +02:00
|
|
|
In practice, these types are usually implementations of <acronym>IEEE</acronym> 754
|
2001-08-24 22:03:45 +02:00
|
|
|
binary floating point (single and double precision,
|
|
|
|
respectively), to the extent that the underlying processor,
|
|
|
|
operating system, and compiler support it.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Inexact means that some values cannot be converted exactly to the
|
|
|
|
internal format and are stored as approximations, so that storing
|
|
|
|
and printing back out a value may show slight discrepancies.
|
|
|
|
Managing these errors and how they propagate through calculations
|
|
|
|
is the subject of an entire branch of mathematics and computer
|
|
|
|
science and will not be discussed further here, except for the
|
|
|
|
following points:
|
|
|
|
<itemizedlist>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
If you require exact storage and calculations (such as for
|
|
|
|
monetary amounts), use the <type>numeric</type> type instead.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
If you want to do complicated calculations with these types
|
|
|
|
for anything important, especially if you rely on certain
|
|
|
|
behavior in boundary cases (infinity, underflow), you should
|
|
|
|
evaluate the implementation carefully.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Comparing two floating point values for equality may or may
|
|
|
|
not work as expected.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</itemizedlist>
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Normally, the <type>real</type> type has a range of at least
|
|
|
|
-1E+37 to +1E+37 with a precision of at least 6. The
|
|
|
|
<type>double precision</type> type normally has a range of around
|
|
|
|
-1E+308 to +1E+308 with a precision of at least 15. Values that
|
|
|
|
are too large or too small will cause an error. Rounding may
|
|
|
|
take place if the precision of an input number is too high.
|
|
|
|
Numbers too close to zero that are not representable as distinct
|
|
|
|
from zero will cause an underflow error.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
</sect2>
|
1999-08-06 15:43:42 +02:00
|
|
|
|
2001-01-13 19:34:51 +01:00
|
|
|
<sect2 id="datatype-serial">
|
2001-08-16 22:38:56 +02:00
|
|
|
<title>The Serial Types</title>
|
1999-08-06 15:43:42 +02:00
|
|
|
|
2001-05-13 00:51:36 +02:00
|
|
|
<indexterm zone="datatype-serial">
|
|
|
|
<primary>serial</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
2001-08-16 22:38:56 +02:00
|
|
|
<indexterm zone="datatype-serial">
|
|
|
|
<primary>serial4</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
|
|
|
<indexterm zone="datatype-serial">
|
|
|
|
<primary>serial8</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
2001-05-13 00:51:36 +02:00
|
|
|
<indexterm>
|
|
|
|
<primary>auto-increment</primary>
|
|
|
|
<see>serial</see>
|
|
|
|
</indexterm>
|
|
|
|
|
|
|
|
<indexterm>
|
|
|
|
<primary>sequences</primary>
|
|
|
|
<secondary>and serial type</secondary>
|
|
|
|
</indexterm>
|
|
|
|
|
1999-08-06 15:43:42 +02:00
|
|
|
<para>
|
2001-09-09 19:21:59 +02:00
|
|
|
The <type>serial</type> data types are not truly types, but are a
|
2001-08-16 22:38:56 +02:00
|
|
|
notational convenience for setting up unique identifier columns
|
|
|
|
in tables.
|
1999-08-06 15:43:42 +02:00
|
|
|
In the current implementation, specifying
|
|
|
|
|
2001-08-24 22:03:45 +02:00
|
|
|
<programlisting>
|
2001-10-09 20:46:00 +02:00
|
|
|
CREATE TABLE <replaceable class="parameter">tablename</replaceable> (
|
|
|
|
<replaceable class="parameter">colname</replaceable> SERIAL
|
|
|
|
);
|
2001-08-24 22:03:45 +02:00
|
|
|
</programlisting>
|
1998-10-14 18:26:31 +02:00
|
|
|
|
1999-08-06 15:43:42 +02:00
|
|
|
is equivalent to specifying:
|
1998-10-14 18:26:31 +02:00
|
|
|
|
2001-08-24 22:03:45 +02:00
|
|
|
<programlisting>
|
1998-10-14 18:26:31 +02:00
|
|
|
CREATE SEQUENCE <replaceable class="parameter">tablename</replaceable>_<replaceable class="parameter">colname</replaceable>_seq;
|
2001-10-09 20:46:00 +02:00
|
|
|
CREATE TABLE <replaceable class="parameter">tablename</replaceable> (
|
|
|
|
<replaceable class="parameter">colname</replaceable> integer DEFAULT nextval('<replaceable class="parameter">tablename</replaceable>_<replaceable class="parameter">colname</replaceable>_seq') UNIQUE NOT NULL
|
|
|
|
);
|
2001-08-24 22:03:45 +02:00
|
|
|
</programlisting>
|
1999-08-06 15:43:42 +02:00
|
|
|
|
2001-08-16 22:38:56 +02:00
|
|
|
Thus, we have created an integer column and arranged for its default
|
|
|
|
values to be assigned from a sequence generator. UNIQUE and NOT NULL
|
|
|
|
constraints are applied to ensure that explicitly-inserted values
|
|
|
|
will never be duplicates, either.
|
2001-10-09 20:46:00 +02:00
|
|
|
</para>
|
2001-08-16 22:38:56 +02:00
|
|
|
|
2001-10-09 20:46:00 +02:00
|
|
|
<important>
|
1999-08-06 15:43:42 +02:00
|
|
|
<para>
|
|
|
|
The implicit sequence created for the <type>serial</type> type will
|
|
|
|
<emphasis>not</emphasis> be automatically removed when the
|
|
|
|
table is dropped.
|
|
|
|
</para>
|
2001-10-09 20:46:00 +02:00
|
|
|
</important>
|
1998-10-14 18:26:31 +02:00
|
|
|
|
2001-08-16 22:38:56 +02:00
|
|
|
<para>
|
|
|
|
The type names <type>serial</type> and <type>serial4</type> are
|
|
|
|
equivalent: both create <type>integer</type> columns. The type
|
2001-08-24 22:03:45 +02:00
|
|
|
names <type>bigserial</type> and <type>serial8</type> works just
|
|
|
|
the same way, except that it creates a <type>bigint</type>
|
|
|
|
column. <type>serial8</type> should be used if you anticipate
|
|
|
|
use of more than 2^31 identifiers over the lifetime of the table.
|
2001-08-16 22:38:56 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
1999-08-06 15:43:42 +02:00
|
|
|
Implicit sequences supporting the <type>serial</type> are
|
|
|
|
not automatically dropped when a table containing a serial type
|
|
|
|
is dropped. So, the following commands executed in order will likely fail:
|
1998-10-14 18:26:31 +02:00
|
|
|
|
2001-08-24 22:03:45 +02:00
|
|
|
<programlisting>
|
1998-10-14 18:26:31 +02:00
|
|
|
CREATE TABLE <replaceable class="parameter">tablename</replaceable> (<replaceable class="parameter">colname</replaceable> SERIAL);
|
|
|
|
DROP TABLE <replaceable class="parameter">tablename</replaceable>;
|
|
|
|
CREATE TABLE <replaceable class="parameter">tablename</replaceable> (<replaceable class="parameter">colname</replaceable> SERIAL);
|
2001-08-24 22:03:45 +02:00
|
|
|
</programlisting>
|
1999-08-06 15:43:42 +02:00
|
|
|
|
|
|
|
The sequence will remain in the database until explicitly dropped using
|
|
|
|
<command>DROP SEQUENCE</command>.
|
|
|
|
</para>
|
|
|
|
</sect2>
|
|
|
|
</sect1>
|
1998-10-14 18:26:31 +02:00
|
|
|
|
2001-01-13 19:34:51 +01:00
|
|
|
<sect1 id="datatype-money">
|
1999-08-06 15:43:42 +02:00
|
|
|
<title>Monetary Type</title>
|
|
|
|
|
|
|
|
<note>
|
2001-01-26 23:04:22 +01:00
|
|
|
<title>Deprecated</title>
|
1999-08-06 15:43:42 +02:00
|
|
|
<para>
|
2001-03-25 00:03:26 +01:00
|
|
|
The <type>money</type> type is deprecated. Use
|
2001-01-26 23:04:22 +01:00
|
|
|
<type>numeric</type> or <type>decimal</type> instead, in
|
|
|
|
combination with the <function>to_char</function> function. The
|
|
|
|
money type may become a locale-aware layer over the
|
|
|
|
<type>numeric</type> type in a future release.
|
1999-08-06 15:43:42 +02:00
|
|
|
</para>
|
|
|
|
</note>
|
|
|
|
|
|
|
|
<para>
|
2001-01-26 23:04:22 +01:00
|
|
|
The <type>money</type> type stores U.S.-style currency with fixed
|
|
|
|
decimal point representation. If
|
|
|
|
<productname>Postgres</productname> is compiled with locale
|
|
|
|
support then the <type>money</type> type uses locale-specific
|
|
|
|
output formatting.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Input is accepted in a variety of formats, including integer and
|
|
|
|
floating point literals, as well as <quote>typical</quote>
|
|
|
|
currency formatting, such as <literal>'$1,000.00'</literal>.
|
|
|
|
Output is in the latter form.
|
1998-12-18 17:11:12 +01:00
|
|
|
</para>
|
1998-10-14 18:26:31 +02:00
|
|
|
|
1999-05-27 17:47:28 +02:00
|
|
|
<para>
|
1999-08-06 15:43:42 +02:00
|
|
|
<table tocentry="1">
|
2001-02-14 20:37:26 +01:00
|
|
|
<title>Monetary Types</title>
|
1999-08-06 15:43:42 +02:00
|
|
|
<tgroup cols="4">
|
|
|
|
<thead>
|
|
|
|
<row>
|
2001-02-14 20:37:26 +01:00
|
|
|
<entry>Type Name</entry>
|
1999-08-06 15:43:42 +02:00
|
|
|
<entry>Storage</entry>
|
|
|
|
<entry>Description</entry>
|
|
|
|
<entry>Range</entry>
|
|
|
|
</row>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<row>
|
|
|
|
<entry>money</entry>
|
|
|
|
<entry>4 bytes</entry>
|
|
|
|
<entry>Fixed-precision</entry>
|
|
|
|
<entry>-21474836.48 to +21474836.47</entry>
|
|
|
|
</row>
|
|
|
|
</tbody>
|
|
|
|
</tgroup>
|
|
|
|
</table>
|
1999-05-27 17:47:28 +02:00
|
|
|
</para>
|
1999-08-06 15:43:42 +02:00
|
|
|
</sect1>
|
1998-03-01 09:16:16 +01:00
|
|
|
|
2001-01-26 23:04:22 +01:00
|
|
|
|
2001-01-13 19:34:51 +01:00
|
|
|
<sect1 id="datatype-character">
|
1999-08-06 15:43:42 +02:00
|
|
|
<title>Character Types</title>
|
|
|
|
|
2001-05-13 00:51:36 +02:00
|
|
|
<indexterm zone="datatype-character">
|
|
|
|
<primary>character strings</primary>
|
|
|
|
<secondary>data types</secondary>
|
|
|
|
</indexterm>
|
|
|
|
|
|
|
|
<indexterm>
|
|
|
|
<primary>strings</primary>
|
|
|
|
<see>character strings</see>
|
|
|
|
</indexterm>
|
|
|
|
|
|
|
|
<indexterm>
|
|
|
|
<primary>text</primary>
|
|
|
|
<see>character strings</see>
|
|
|
|
</indexterm>
|
|
|
|
|
1999-08-06 15:43:42 +02:00
|
|
|
<table tocentry="1">
|
2001-02-14 20:37:26 +01:00
|
|
|
<title>Character Types</title>
|
2001-08-08 00:41:49 +02:00
|
|
|
<tgroup cols="2">
|
1999-08-06 15:43:42 +02:00
|
|
|
<thead>
|
|
|
|
<row>
|
2001-08-08 00:41:49 +02:00
|
|
|
<entry>Type name</entry>
|
1999-08-06 15:43:42 +02:00
|
|
|
<entry>Description</entry>
|
|
|
|
</row>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<row>
|
2001-09-09 19:21:59 +02:00
|
|
|
<entry><type>character(<replaceable>n</>)</type>, <type>char(<replaceable>n</>)</type></entry>
|
2001-01-13 19:34:51 +01:00
|
|
|
<entry>Fixed-length blank padded</entry>
|
1999-08-06 15:43:42 +02:00
|
|
|
</row>
|
|
|
|
<row>
|
2001-09-09 19:21:59 +02:00
|
|
|
<entry><type>character varying(<replaceable>n</>)</type>, <type>varchar(<replaceable>n</>)</type></entry>
|
2001-01-13 19:34:51 +01:00
|
|
|
<entry>Variable-length with limit</entry>
|
1999-08-06 15:43:42 +02:00
|
|
|
</row>
|
|
|
|
<row>
|
2001-09-09 19:21:59 +02:00
|
|
|
<entry><type>text</type></entry>
|
2000-12-03 15:47:18 +01:00
|
|
|
<entry>Variable unlimited length</entry>
|
1999-08-06 15:43:42 +02:00
|
|
|
</row>
|
2001-09-04 05:17:54 +02:00
|
|
|
</tbody>
|
1999-08-06 15:43:42 +02:00
|
|
|
</tgroup>
|
|
|
|
</table>
|
2001-01-13 19:34:51 +01:00
|
|
|
|
2001-05-21 18:54:46 +02:00
|
|
|
<para>
|
|
|
|
<acronym>SQL</acronym> defines two primary character types:
|
|
|
|
<type>character(<replaceable>n</>)</type> and <type>character
|
|
|
|
varying(<replaceable>n</>)</type>, where <replaceable>n</> is a
|
|
|
|
positive integer. Both of these types can store strings up to
|
|
|
|
<replaceable>n</> characters in length. An attempt to store a
|
|
|
|
longer string into a column of these types will result in an
|
|
|
|
error, unless the excess characters are all spaces, in which case
|
|
|
|
the string will be truncated to the maximum length. (This
|
|
|
|
somewhat bizarre exception is required by the SQL standard.) If
|
|
|
|
the string to be stored is shorter than the declared length,
|
|
|
|
values of type <type>character</type> will be space-padded; values
|
|
|
|
of type <type>character varying</type> will simply store the
|
|
|
|
shorter string.
|
1999-08-06 15:43:42 +02:00
|
|
|
</para>
|
1998-12-18 17:11:12 +01:00
|
|
|
|
2001-05-21 18:54:46 +02:00
|
|
|
<note>
|
|
|
|
<para>
|
|
|
|
Prior to PostgreSQL 7.2, strings that were too long were silently
|
|
|
|
truncated, no error was raised.
|
|
|
|
</para>
|
|
|
|
</note>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
The notations <type>char(<replaceable>n</>)</type> and
|
|
|
|
<type>varchar(<replaceable>n</>)</type> are aliases for
|
|
|
|
<type>character(<replaceable>n</>)</type> and <type>character
|
|
|
|
varying(<replaceable>n</>)</type>,
|
|
|
|
respectively. <type>character</type> without length specifier is
|
|
|
|
equivalent to <type>character(1)</type>; if <type>character
|
|
|
|
varying</type> is used without length specifier, the type accepts
|
|
|
|
strings of any size. The latter is a PostgreSQL extension.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
In addition, <productname>PostgreSQL</productname> supports the
|
|
|
|
more general <type>text</type> type, which stores strings of any
|
|
|
|
length. Unlike <type>character varying</type>, <type>text</type>
|
|
|
|
does not require an explicit declared upper limit on the size of
|
|
|
|
the string. Although the type <type>text</type> is not in the SQL
|
|
|
|
standard, many other RDBMS packages have it as well.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2001-08-08 00:41:49 +02:00
|
|
|
The storage requirement for data of these types is 4 bytes plus
|
|
|
|
the actual string, and in case of <type>character</type> plus the
|
|
|
|
padding. Long strings will actually be compressed by the system
|
|
|
|
automatically. In any case, the longest possible character string
|
|
|
|
that can be stored is about 1 GB. (The maximum value that will be
|
|
|
|
allowed for <replaceable>n</> in the data type declaration is
|
|
|
|
actually larger than that. It wouldn't be very useful to change
|
2001-09-09 19:21:59 +02:00
|
|
|
this because with multibyte character encodings the number of
|
2001-08-08 00:41:49 +02:00
|
|
|
characters and bytes can be quite different anyway.)
|
2001-05-21 18:54:46 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<tip>
|
|
|
|
<para>
|
|
|
|
There are no performance differences between these three types,
|
|
|
|
apart from the increased storage size when using the blank-padded
|
|
|
|
type.
|
|
|
|
</para>
|
|
|
|
</tip>
|
|
|
|
|
2001-08-08 00:41:49 +02:00
|
|
|
<para>
|
|
|
|
Refer to <xref linkend="sql-syntax-strings"> for information about
|
|
|
|
the syntax of string literals, and to <xref linkend="functions">
|
|
|
|
for information about available operators and functions.
|
|
|
|
</para>
|
|
|
|
|
2001-05-21 18:54:46 +02:00
|
|
|
<example>
|
|
|
|
<title>Using the character types</title>
|
|
|
|
|
|
|
|
<programlisting>
|
|
|
|
CREATE TABLE test1 (a character(4));
|
|
|
|
INSERT INTO test1 VALUES ('ok');
|
|
|
|
SELECT a, char_length(a) FROM test1; -- <co id="co.datatype-char">
|
|
|
|
<computeroutput>
|
|
|
|
a | char_length
|
|
|
|
------+-------------
|
|
|
|
ok | 4
|
|
|
|
</computeroutput>
|
|
|
|
|
|
|
|
CREATE TABLE test2 (b varchar(5));
|
|
|
|
INSERT INTO test2 VALUES ('ok');
|
|
|
|
INSERT INTO test2 VALUES ('good ');
|
|
|
|
INSERT INTO test2 VALUES ('too long');
|
|
|
|
<computeroutput>ERROR: value too long for type character varying(5)</computeroutput>
|
|
|
|
SELECT b, char_length(b) FROM test2;
|
|
|
|
<computeroutput>
|
|
|
|
b | char_length
|
|
|
|
-------+-------------
|
|
|
|
ok | 2
|
|
|
|
good | 5
|
|
|
|
</computeroutput>
|
|
|
|
</programlisting>
|
|
|
|
<calloutlist>
|
|
|
|
<callout arearefs="co.datatype-char">
|
|
|
|
<para>
|
|
|
|
The <function>char_length</function> function is discussed in
|
|
|
|
<xref linkend="functions-string">.
|
|
|
|
</para>
|
|
|
|
</callout>
|
|
|
|
</calloutlist>
|
|
|
|
</example>
|
|
|
|
|
1999-05-27 17:47:28 +02:00
|
|
|
<para>
|
2001-01-13 19:34:51 +01:00
|
|
|
There are two other fixed-length character types in
|
|
|
|
<productname>Postgres</productname>. The <type>name</type> type
|
|
|
|
exists <emphasis>only</emphasis> for storage of internal catalog
|
|
|
|
names and is not intended for use by the general user. Its length
|
|
|
|
is currently defined as 32 bytes (31 characters plus terminator)
|
|
|
|
but should be referenced using the macro
|
|
|
|
<symbol>NAMEDATALEN</symbol>. The length is set at compile time
|
|
|
|
(and is therefore adjustable for special uses); the default
|
|
|
|
maximum length may change in a future release. The type
|
|
|
|
<type>"char"</type> (note the quotes) is different from
|
|
|
|
<type>char(1)</type> in that it only uses one byte of storage. It
|
|
|
|
is internally used in the system catalogs as a poor-man's
|
|
|
|
enumeration type.
|
1999-05-27 17:47:28 +02:00
|
|
|
</para>
|
1998-03-01 09:16:16 +01:00
|
|
|
|
1999-08-06 15:43:42 +02:00
|
|
|
<table tocentry="1">
|
2001-02-14 20:37:26 +01:00
|
|
|
<title>Specialty Character Type</title>
|
1999-08-06 15:43:42 +02:00
|
|
|
<tgroup cols="3">
|
|
|
|
<thead>
|
|
|
|
<row>
|
2001-02-14 20:37:26 +01:00
|
|
|
<entry>Type Name</entry>
|
1999-08-06 15:43:42 +02:00
|
|
|
<entry>Storage</entry>
|
|
|
|
<entry>Description</entry>
|
|
|
|
</row>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
2001-01-13 19:34:51 +01:00
|
|
|
<row>
|
|
|
|
<entry>"char"</entry>
|
|
|
|
<entry>1 byte</entry>
|
|
|
|
<entry>Single character internal type</entry>
|
|
|
|
</row>
|
1999-08-06 15:43:42 +02:00
|
|
|
<row>
|
|
|
|
<entry>name</entry>
|
|
|
|
<entry>32 bytes</entry>
|
2000-03-14 23:52:53 +01:00
|
|
|
<entry>Thirty-one character internal type</entry>
|
1999-08-06 15:43:42 +02:00
|
|
|
</row>
|
|
|
|
</tbody>
|
|
|
|
</tgroup>
|
|
|
|
</table>
|
|
|
|
|
|
|
|
</sect1>
|
1998-12-18 17:11:12 +01:00
|
|
|
|
2001-09-09 19:21:59 +02:00
|
|
|
<sect1 id="datatype-binary">
|
|
|
|
<title>Binary Data</title>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
The <type>bytea</type> data type allows storage of binary data,
|
|
|
|
specifically allowing storage of NULLs which are entered as
|
|
|
|
<literal>'\\000'</>. The first backslash is interpreted by the
|
|
|
|
single quotes, and the second is recognized by <type>bytea</> and
|
|
|
|
precedes a three digit octal value. For a similar reason, a
|
|
|
|
backslash must be entered into a field as <literal>'\\\\'</> or
|
|
|
|
<literal>'\\134'</>. You may also have to escape line feeds and
|
|
|
|
carriage return if your interface automatically translates these. It
|
|
|
|
can store values of any length. <type>Bytea</> is a non-standard
|
|
|
|
data type.
|
|
|
|
</para>
|
|
|
|
</sect1>
|
|
|
|
|
2001-01-13 19:34:51 +01:00
|
|
|
<sect1 id="datatype-datetime">
|
1999-05-04 04:22:13 +02:00
|
|
|
<title>Date/Time Types</title>
|
|
|
|
|
|
|
|
<para>
|
2000-05-02 22:02:03 +02:00
|
|
|
<productname>Postgres</productname> supports the full set of
|
2000-01-23 02:27:39 +01:00
|
|
|
<acronym>SQL</acronym> date and time types.
|
1999-05-04 04:22:13 +02:00
|
|
|
</para>
|
1998-10-27 07:14:41 +01:00
|
|
|
|
1999-05-04 04:22:13 +02:00
|
|
|
<para>
|
|
|
|
<table tocentry="1">
|
2001-02-14 20:37:26 +01:00
|
|
|
<title>Date/Time Types</title>
|
2001-10-09 20:46:00 +02:00
|
|
|
<tgroup cols="6">
|
1999-05-04 04:22:13 +02:00
|
|
|
<thead>
|
|
|
|
<row>
|
2000-01-23 02:27:39 +01:00
|
|
|
<entry>Type</entry>
|
|
|
|
<entry>Description</entry>
|
1999-05-04 04:22:13 +02:00
|
|
|
<entry>Storage</entry>
|
2000-01-23 02:27:39 +01:00
|
|
|
<entry>Earliest</entry>
|
|
|
|
<entry>Latest</entry>
|
|
|
|
<entry>Resolution</entry>
|
1999-05-04 04:22:13 +02:00
|
|
|
</row>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<row>
|
2001-09-28 10:15:35 +02:00
|
|
|
<entry><type>timestamp without time zone</type></entry>
|
2000-05-02 22:02:03 +02:00
|
|
|
<entry>both date and time</entry>
|
2000-01-23 02:27:39 +01:00
|
|
|
<entry>8 bytes</entry>
|
|
|
|
<entry>4713 BC</entry>
|
|
|
|
<entry>AD 1465001</entry>
|
2001-02-14 20:37:26 +01:00
|
|
|
<entry>1 microsecond / 14 digits</entry>
|
1999-05-04 04:22:13 +02:00
|
|
|
</row>
|
2000-03-14 23:52:53 +01:00
|
|
|
<row>
|
2000-07-14 17:26:21 +02:00
|
|
|
<entry><type>timestamp [ with time zone ]</type></entry>
|
2001-09-28 10:15:35 +02:00
|
|
|
<entry>both date and time</entry>
|
2000-03-14 23:52:53 +01:00
|
|
|
<entry>8 bytes</entry>
|
2001-09-28 10:15:35 +02:00
|
|
|
<entry>4713 BC</entry>
|
|
|
|
<entry>AD 1465001</entry>
|
2001-02-14 20:37:26 +01:00
|
|
|
<entry>1 microsecond / 14 digits</entry>
|
2000-03-14 23:52:53 +01:00
|
|
|
</row>
|
1999-05-04 04:22:13 +02:00
|
|
|
<row>
|
2000-01-23 02:27:39 +01:00
|
|
|
<entry><type>interval</type></entry>
|
|
|
|
<entry>for time intervals</entry>
|
|
|
|
<entry>12 bytes</entry>
|
|
|
|
<entry>-178000000 years</entry>
|
|
|
|
<entry>178000000 years</entry>
|
2000-08-23 07:59:11 +02:00
|
|
|
<entry>1 microsecond</entry>
|
1999-05-04 04:22:13 +02:00
|
|
|
</row>
|
|
|
|
<row>
|
2000-01-23 02:27:39 +01:00
|
|
|
<entry><type>date</type></entry>
|
2000-05-02 22:02:03 +02:00
|
|
|
<entry>dates only</entry>
|
2000-01-23 02:27:39 +01:00
|
|
|
<entry>4 bytes</entry>
|
|
|
|
<entry>4713 BC</entry>
|
|
|
|
<entry>32767 AD</entry>
|
|
|
|
<entry>1 day</entry>
|
1999-05-04 04:22:13 +02:00
|
|
|
</row>
|
|
|
|
<row>
|
2000-07-14 17:26:21 +02:00
|
|
|
<entry><type>time [ without time zone ]</type></entry>
|
2000-05-02 22:02:03 +02:00
|
|
|
<entry>times of day only</entry>
|
2001-08-31 03:55:25 +02:00
|
|
|
<entry>8 bytes</entry>
|
2000-01-23 02:27:39 +01:00
|
|
|
<entry>00:00:00.00</entry>
|
|
|
|
<entry>23:59:59.99</entry>
|
|
|
|
<entry>1 microsecond</entry>
|
1999-05-04 04:22:13 +02:00
|
|
|
</row>
|
2000-03-14 23:52:53 +01:00
|
|
|
<row>
|
|
|
|
<entry><type>time with time zone</type></entry>
|
2000-05-02 22:02:03 +02:00
|
|
|
<entry>times of day only</entry>
|
2001-08-31 03:55:25 +02:00
|
|
|
<entry>12 bytes</entry>
|
2000-03-14 23:52:53 +01:00
|
|
|
<entry>00:00:00.00+12</entry>
|
|
|
|
<entry>23:59:59.99-12</entry>
|
|
|
|
<entry>1 microsecond</entry>
|
|
|
|
</row>
|
1999-05-04 04:22:13 +02:00
|
|
|
</tbody>
|
|
|
|
</tgroup>
|
|
|
|
</table>
|
|
|
|
|
2000-01-23 02:27:39 +01:00
|
|
|
<note>
|
|
|
|
<para>
|
2001-09-28 10:15:35 +02:00
|
|
|
Time zones, and time zone conventions, are influenced by
|
|
|
|
political conventions, not just physical effects. Time zones have
|
|
|
|
become somewhat standardized during the 1900's, but continue to
|
|
|
|
be prone to arbitrary changes with time.
|
|
|
|
<productname>PostgreSQL</productname> uses your operating
|
|
|
|
system's underlying features to provide time zone
|
|
|
|
support, and these systems usually contain information for only
|
|
|
|
the time period 1902 through 2038 (corresponding to the full
|
|
|
|
range of conventional Unix system time).
|
|
|
|
<type>timestamp with time zone</type> will use time zone
|
|
|
|
information only within that year range, and assumes that times
|
|
|
|
are in UTC outside that range.
|
2000-01-23 02:27:39 +01:00
|
|
|
</para>
|
|
|
|
</note>
|
1999-05-04 04:22:13 +02:00
|
|
|
</para>
|
1998-10-27 07:14:41 +01:00
|
|
|
|
2001-09-28 10:15:35 +02:00
|
|
|
<para>
|
|
|
|
To ensure compatibility to earlier versions of <productname>Postgres</productname>
|
|
|
|
we also continue to provide <type>datetime</type>
|
|
|
|
(equivalent to <type>timestamp</type>) and
|
|
|
|
<type>timespan</type> (equivalent to <type>interval</type>),
|
|
|
|
however support for these is now restricted to having an
|
|
|
|
implicit translation to <type>timestamp</type> and
|
|
|
|
<type>interval</type>.
|
|
|
|
The types <type>abstime</type>
|
|
|
|
and <type>reltime</type> are lower precision types which are used internally.
|
|
|
|
You are discouraged from using any of these types in new
|
|
|
|
applications and are encouraged to move any old
|
|
|
|
ones over when appropriate. Any or all of these internal types
|
|
|
|
might disappear in a future release.
|
|
|
|
</para>
|
1998-03-01 09:16:16 +01:00
|
|
|
|
2001-01-13 19:34:51 +01:00
|
|
|
<sect2 id="datatype-datetime-input">
|
1999-01-19 17:08:26 +01:00
|
|
|
<title>Date/Time Input</title>
|
1998-03-01 09:16:16 +01:00
|
|
|
|
1999-01-19 17:08:26 +01:00
|
|
|
<para>
|
2000-01-23 02:27:39 +01:00
|
|
|
Date and time input is accepted in almost any reasonable format, including
|
2000-03-14 23:52:53 +01:00
|
|
|
<acronym>ISO-8601</acronym>, <acronym>SQL</acronym>-compatible,
|
2000-01-23 02:27:39 +01:00
|
|
|
traditional <productname>Postgres</productname>, and others.
|
|
|
|
The ordering of month and day in date input can be ambiguous, therefore a setting
|
2000-05-02 22:02:03 +02:00
|
|
|
exists to specify how it should be interpreted in ambiguous cases. The command
|
2000-01-23 02:27:39 +01:00
|
|
|
<literal>SET DateStyle TO 'US'</literal> or <literal>SET DateStyle TO 'NonEuropean'</literal>
|
2001-09-13 17:55:24 +02:00
|
|
|
specifies the variant <quote>month before day</quote>, the command
|
2000-01-23 02:27:39 +01:00
|
|
|
<literal>SET DateStyle TO 'European'</literal> sets the variant
|
2001-09-13 17:55:24 +02:00
|
|
|
<quote>day before month</quote>. The <literal>ISO</literal> style
|
2000-03-14 23:52:53 +01:00
|
|
|
is the default but this default can be changed at compile time or at run time.
|
1998-12-18 17:11:12 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2001-01-13 19:34:51 +01:00
|
|
|
See <xref linkend="datetime-appendix">
|
2000-01-23 02:27:39 +01:00
|
|
|
for the exact parsing rules of date/time input and for the recognized time zones.
|
1999-01-19 17:08:26 +01:00
|
|
|
</para>
|
1998-12-18 17:11:12 +01:00
|
|
|
|
1999-01-19 17:08:26 +01:00
|
|
|
<para>
|
2001-01-26 23:04:22 +01:00
|
|
|
Remember that any date or time input needs to be enclosed into
|
|
|
|
single quotes, like text strings. Refer to <xref
|
|
|
|
linkend="sql-syntax-constants-generic"> for more information.
|
|
|
|
SQL requires the following syntax
|
|
|
|
<synopsis>
|
|
|
|
<replaceable>type</replaceable> '<replaceable>value</replaceable>'
|
|
|
|
</synopsis>
|
|
|
|
but <productname>Postgres</productname> is more flexible.
|
1999-01-19 17:08:26 +01:00
|
|
|
</para>
|
|
|
|
|
2000-01-23 02:27:39 +01:00
|
|
|
<sect3>
|
2001-09-09 19:21:59 +02:00
|
|
|
<title><type>date</type></title>
|
2001-05-13 00:51:36 +02:00
|
|
|
|
|
|
|
<indexterm>
|
|
|
|
<primary>date</primary>
|
|
|
|
<secondary>data type</secondary>
|
|
|
|
</indexterm>
|
|
|
|
|
1999-01-19 17:08:26 +01:00
|
|
|
<para>
|
2000-01-23 02:27:39 +01:00
|
|
|
The following are possible inputs for the <type>date</type> type.
|
2000-03-14 23:52:53 +01:00
|
|
|
|
1999-01-19 17:08:26 +01:00
|
|
|
<table tocentry="1">
|
2001-02-14 20:37:26 +01:00
|
|
|
<title>Date Input</title>
|
1999-01-19 17:08:26 +01:00
|
|
|
<tgroup cols="2">
|
|
|
|
<thead>
|
|
|
|
<row>
|
|
|
|
<entry>Example</entry>
|
|
|
|
<entry>Description</entry>
|
|
|
|
</row>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<row>
|
|
|
|
<entry>January 8, 1999</entry>
|
2000-01-23 02:27:39 +01:00
|
|
|
<entry>Unambiguous</entry>
|
1999-01-19 17:08:26 +01:00
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>1999-01-08</entry>
|
2000-01-23 02:27:39 +01:00
|
|
|
<entry>ISO-8601 format, preferred</entry>
|
1999-01-19 17:08:26 +01:00
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>1/8/1999</entry>
|
|
|
|
<entry>US; read as August 1 in European mode</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>8/1/1999</entry>
|
|
|
|
<entry>European; read as August 1 in US mode</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>1/18/1999</entry>
|
|
|
|
<entry>US; read as January 18 in any mode</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>19990108</entry>
|
|
|
|
<entry>ISO-8601 year, month, day</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>990108</entry>
|
|
|
|
<entry>ISO-8601 year, month, day</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>1999.008</entry>
|
|
|
|
<entry>Year and day of year</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>99008</entry>
|
|
|
|
<entry>Year and day of year</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>January 8, 99 BC</entry>
|
2000-05-02 22:02:03 +02:00
|
|
|
<entry>Year 99 before the Common Era</entry>
|
1999-01-19 17:08:26 +01:00
|
|
|
</row>
|
|
|
|
</tbody>
|
|
|
|
</tgroup>
|
|
|
|
</table>
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
<table tocentry="1">
|
2001-02-14 20:37:26 +01:00
|
|
|
<title>Month Abbreviations</title>
|
1999-01-19 17:08:26 +01:00
|
|
|
<tgroup cols="2">
|
|
|
|
<thead>
|
|
|
|
<row>
|
|
|
|
<entry>Month</entry>
|
|
|
|
<entry>Abbreviations</entry>
|
|
|
|
</row>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<row>
|
|
|
|
<entry>April</entry>
|
|
|
|
<entry>Apr</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>August</entry>
|
|
|
|
<entry>Aug</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>December</entry>
|
|
|
|
<entry>Dec</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>February</entry>
|
|
|
|
<entry>Feb</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>January</entry>
|
|
|
|
<entry>Jan</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>July</entry>
|
|
|
|
<entry>Jul</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>June</entry>
|
|
|
|
<entry>Jun</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>March</entry>
|
|
|
|
<entry>Mar</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>November</entry>
|
|
|
|
<entry>Nov</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>October</entry>
|
|
|
|
<entry>Oct</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>September</entry>
|
|
|
|
<entry>Sep, Sept</entry>
|
|
|
|
</row>
|
|
|
|
</tbody>
|
|
|
|
</tgroup>
|
|
|
|
</table>
|
|
|
|
|
|
|
|
<note>
|
|
|
|
<para>
|
|
|
|
The month <literal>May</literal> has no explicit abbreviation, for obvious reasons.
|
|
|
|
</para>
|
|
|
|
</note>
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
<table tocentry="1">
|
2001-02-14 20:37:26 +01:00
|
|
|
<title>Day of the Week Abbreviations</title>
|
1999-01-19 17:08:26 +01:00
|
|
|
<tgroup cols="2">
|
|
|
|
<thead>
|
|
|
|
<row>
|
|
|
|
<entry>Day</entry>
|
|
|
|
<entry>Abbreviation</entry>
|
|
|
|
</row>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<row>
|
|
|
|
<entry>Sunday</entry>
|
|
|
|
<entry>Sun</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>Monday</entry>
|
|
|
|
<entry>Mon</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>Tuesday</entry>
|
|
|
|
<entry>Tue, Tues</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>Wednesday</entry>
|
|
|
|
<entry>Wed, Weds</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>Thursday</entry>
|
|
|
|
<entry>Thu, Thur, Thurs</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>Friday</entry>
|
|
|
|
<entry>Fri</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>Saturday</entry>
|
|
|
|
<entry>Sat</entry>
|
|
|
|
</row>
|
|
|
|
</tbody>
|
|
|
|
</tgroup>
|
|
|
|
</table>
|
|
|
|
</para>
|
2000-01-23 02:27:39 +01:00
|
|
|
</sect3>
|
1999-01-19 17:08:26 +01:00
|
|
|
|
2000-01-23 02:27:39 +01:00
|
|
|
<sect3>
|
2001-09-09 19:21:59 +02:00
|
|
|
<title><type>time [ without time zone ]</type></title>
|
2000-07-14 17:26:21 +02:00
|
|
|
|
2001-05-13 00:51:36 +02:00
|
|
|
<indexterm>
|
|
|
|
<primary>time</primary>
|
|
|
|
<secondary>data type</secondary>
|
|
|
|
</indexterm>
|
2001-09-28 10:15:35 +02:00
|
|
|
<indexterm>
|
|
|
|
<primary>time without time zone</primary>
|
|
|
|
<secondary>time</secondary>
|
|
|
|
</indexterm>
|
2001-05-13 00:51:36 +02:00
|
|
|
|
2000-07-14 17:26:21 +02:00
|
|
|
<para>
|
|
|
|
Per SQL99, this type can be referenced as <type>time</type> and
|
|
|
|
as <type>time without time zone</type>.
|
|
|
|
</para>
|
|
|
|
|
2000-03-14 23:52:53 +01:00
|
|
|
<para>
|
|
|
|
The following are valid <type>time</type> inputs.
|
|
|
|
|
|
|
|
<table tocentry="1">
|
2001-02-14 20:37:26 +01:00
|
|
|
<title>Time Input</title>
|
2000-03-14 23:52:53 +01:00
|
|
|
<tgroup cols="2">
|
|
|
|
<thead>
|
|
|
|
<row>
|
|
|
|
<entry>Example</entry>
|
|
|
|
<entry>Description</entry>
|
|
|
|
</row>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<row>
|
|
|
|
<entry>04:05:06.789</entry>
|
|
|
|
<entry>ISO-8601</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>04:05:06</entry>
|
|
|
|
<entry>ISO-8601</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>04:05</entry>
|
|
|
|
<entry>ISO-8601</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>040506</entry>
|
|
|
|
<entry>ISO-8601</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>04:05 AM</entry>
|
|
|
|
<entry>Same as 04:05; AM does not affect value</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>04:05 PM</entry>
|
|
|
|
<entry>Same as 16:05; input hour must be <= 12</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>z</entry>
|
|
|
|
<entry>Same as 00:00:00</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>zulu</entry>
|
|
|
|
<entry>Same as 00:00:00</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>allballs</entry>
|
|
|
|
<entry>Same as 00:00:00</entry>
|
|
|
|
</row>
|
|
|
|
</tbody>
|
|
|
|
</tgroup>
|
|
|
|
</table>
|
|
|
|
</para>
|
|
|
|
</sect3>
|
|
|
|
|
|
|
|
<sect3>
|
2001-09-09 19:21:59 +02:00
|
|
|
<title><type>time with time zone</type></title>
|
2000-05-02 22:02:03 +02:00
|
|
|
|
2001-09-28 10:15:35 +02:00
|
|
|
<indexterm>
|
|
|
|
<primary>time with time zone</primary>
|
|
|
|
<secondary>data type</secondary>
|
|
|
|
</indexterm>
|
|
|
|
<indexterm>
|
|
|
|
<primary>time</primary>
|
|
|
|
<secondary>data type</secondary>
|
|
|
|
</indexterm>
|
|
|
|
|
2000-03-14 23:52:53 +01:00
|
|
|
<para>
|
|
|
|
This type is defined by SQL92, but the definition exhibits
|
2001-09-28 10:15:35 +02:00
|
|
|
properties which lead to questionable usefulness. In
|
2000-03-14 23:52:53 +01:00
|
|
|
most cases, a combination of <type>date</type>,
|
2001-09-28 10:15:35 +02:00
|
|
|
<type>time</type>, <type>timestamp without time zone</type>
|
|
|
|
and <type>timestamp with time zone</type>
|
2000-03-14 23:52:53 +01:00
|
|
|
should provide a complete range of date/time functionality
|
2000-05-02 22:02:03 +02:00
|
|
|
required by any application.
|
2000-03-14 23:52:53 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
<type>time with time zone</type> accepts all input also legal
|
|
|
|
for the <type>time</type> type, appended with a legal time zone,
|
|
|
|
as follows:
|
|
|
|
|
|
|
|
<table tocentry="1">
|
2001-02-14 20:37:26 +01:00
|
|
|
<title>Time With Time Zone Input</title>
|
2000-03-14 23:52:53 +01:00
|
|
|
<tgroup cols="2">
|
1999-01-19 17:08:26 +01:00
|
|
|
<thead>
|
|
|
|
<row>
|
|
|
|
<entry>Example</entry>
|
|
|
|
<entry>Description</entry>
|
|
|
|
</row>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<row>
|
2000-03-14 23:52:53 +01:00
|
|
|
<entry>04:05:06.789-8</entry>
|
2000-01-23 02:27:39 +01:00
|
|
|
<entry>ISO-8601</entry>
|
1999-01-19 17:08:26 +01:00
|
|
|
</row>
|
|
|
|
<row>
|
2000-03-14 23:52:53 +01:00
|
|
|
<entry>04:05:06-08:00</entry>
|
1999-01-19 17:08:26 +01:00
|
|
|
<entry>ISO-8601</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
2000-03-14 23:52:53 +01:00
|
|
|
<entry>04:05-08:00</entry>
|
1999-01-19 17:08:26 +01:00
|
|
|
<entry>ISO-8601</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
2000-03-26 20:32:30 +02:00
|
|
|
<entry>040506-08</entry>
|
1999-01-19 17:08:26 +01:00
|
|
|
<entry>ISO-8601</entry>
|
|
|
|
</row>
|
|
|
|
</tbody>
|
|
|
|
</tgroup>
|
|
|
|
</table>
|
|
|
|
</para>
|
2000-03-14 23:52:53 +01:00
|
|
|
|
|
|
|
<para>
|
2001-01-13 19:34:51 +01:00
|
|
|
Refer to <xref linkend="datatype-timezone-table"> for
|
2000-03-14 23:52:53 +01:00
|
|
|
more examples of time zones.
|
|
|
|
</para>
|
2000-01-23 02:27:39 +01:00
|
|
|
</sect3>
|
|
|
|
|
|
|
|
<sect3>
|
2001-09-28 10:15:35 +02:00
|
|
|
<title><type>timestamp without time zone</type></title>
|
|
|
|
|
|
|
|
<indexterm>
|
|
|
|
<primary>timestamp without time zone</primary>
|
|
|
|
<secondary>data type</secondary>
|
|
|
|
</indexterm>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Valid input for the <type>timestamp without time zone</type>
|
|
|
|
type consists of a concatenation
|
|
|
|
of a date and a time, followed by an optional <literal>AD</literal> or
|
|
|
|
<literal>BC</literal>, followed by an optional time zone. (See below.)
|
|
|
|
Thus
|
|
|
|
|
|
|
|
<programlisting>
|
|
|
|
1999-01-08 04:05:06
|
|
|
|
</programlisting>
|
|
|
|
|
|
|
|
is a valid <type>timestamp without time zone</type> value that
|
|
|
|
is <acronym>ISO</acronym>-compliant.
|
|
|
|
In addition, the wide-spread format
|
|
|
|
|
|
|
|
<programlisting>
|
|
|
|
January 8 04:05:06 1999 PST
|
|
|
|
</programlisting>
|
|
|
|
is supported.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
For <type>timestamp without time zone</type>, any explicit time
|
|
|
|
zone specified in the input is silently swallowed. That is, the
|
|
|
|
resulting date/time value is derived from the explicit date/time
|
|
|
|
fields in the input value, and is not adjusted for time zone.
|
|
|
|
</para>
|
|
|
|
</sect3>
|
|
|
|
|
|
|
|
<sect3>
|
|
|
|
<title><type>timestamp with time zone</type></title>
|
2000-05-02 22:02:03 +02:00
|
|
|
|
2001-05-13 00:51:36 +02:00
|
|
|
<indexterm>
|
|
|
|
<primary>timestamp</primary>
|
|
|
|
<secondary>data type</secondary>
|
|
|
|
</indexterm>
|
|
|
|
|
2000-05-02 22:02:03 +02:00
|
|
|
<para>
|
|
|
|
Valid input for the <type>timestamp</type> type consists of a concatenation
|
|
|
|
of a date and a time, followed by an optional <literal>AD</literal> or
|
|
|
|
<literal>BC</literal>, followed by an optional time zone. (See below.)
|
|
|
|
Thus
|
|
|
|
|
|
|
|
<programlisting>
|
2000-01-23 02:27:39 +01:00
|
|
|
1999-01-08 04:05:06 -8:00
|
2000-05-02 22:02:03 +02:00
|
|
|
</programlisting>
|
|
|
|
|
2000-12-22 19:57:50 +01:00
|
|
|
is a valid <type>timestamp</type> value that is <acronym>ISO</acronym>-compliant.
|
2000-05-02 22:02:03 +02:00
|
|
|
In addition, the wide-spread format
|
|
|
|
|
|
|
|
<programlisting>
|
2000-01-23 02:27:39 +01:00
|
|
|
January 8 04:05:06 1999 PST
|
2000-05-02 22:02:03 +02:00
|
|
|
</programlisting>
|
|
|
|
is supported.
|
|
|
|
</para>
|
1999-01-19 17:08:26 +01:00
|
|
|
|
2000-05-02 22:02:03 +02:00
|
|
|
<para>
|
2001-01-13 19:34:51 +01:00
|
|
|
<table tocentry="1" id="datatype-timezone-table">
|
2001-02-14 20:37:26 +01:00
|
|
|
<title>Time Zone Input</title>
|
2000-05-02 22:02:03 +02:00
|
|
|
<tgroup cols="2">
|
|
|
|
<thead>
|
|
|
|
<row>
|
|
|
|
<entry>Time Zone</entry>
|
|
|
|
<entry>Description</entry>
|
|
|
|
</row>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<row>
|
|
|
|
<entry>PST</entry>
|
|
|
|
<entry>Pacific Standard Time</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>-8:00</entry>
|
|
|
|
<entry>ISO-8601 offset for PST</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>-800</entry>
|
|
|
|
<entry>ISO-8601 offset for PST</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>-8</entry>
|
|
|
|
<entry>ISO-8601 offset for PST</entry>
|
|
|
|
</row>
|
|
|
|
</tbody>
|
|
|
|
</tgroup>
|
|
|
|
</table>
|
|
|
|
</para>
|
2000-01-23 02:27:39 +01:00
|
|
|
</sect3>
|
1999-01-19 17:08:26 +01:00
|
|
|
|
2000-01-23 02:27:39 +01:00
|
|
|
<sect3>
|
2001-09-09 19:21:59 +02:00
|
|
|
<title><type>interval</type></title>
|
2000-05-02 22:02:03 +02:00
|
|
|
|
2001-05-13 00:51:36 +02:00
|
|
|
<indexterm>
|
|
|
|
<primary>interval</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
1999-01-19 17:08:26 +01:00
|
|
|
<para>
|
2000-01-23 02:27:39 +01:00
|
|
|
<type>interval</type>s can be specified with the following syntax:
|
2000-05-02 22:02:03 +02:00
|
|
|
|
|
|
|
<programlisting>
|
2000-01-23 02:27:39 +01:00
|
|
|
Quantity Unit [Quantity Unit...] [Direction]
|
|
|
|
@ Quantity Unit [Direction]
|
2000-05-02 22:02:03 +02:00
|
|
|
</programlisting>
|
|
|
|
|
|
|
|
where: <literal>Quantity</literal> is ..., <literal>-1</literal>,
|
|
|
|
<literal>0</literal>, <literal>1</literal>, <literal>2</literal>, ...;
|
|
|
|
<literal>Unit</literal> is <literal>second</literal>,
|
|
|
|
<literal>minute</literal>, <literal>hour</literal>, <literal>day</literal>,
|
|
|
|
<literal>week</literal>, <literal>month</literal>, <literal>year</literal>,
|
|
|
|
<literal>decade</literal>, <literal>century</literal>, <literal>millennium</literal>,
|
|
|
|
or abbreviations or plurals of these units;
|
|
|
|
<literal>Direction</literal> can be <literal>ago</literal> or
|
|
|
|
empty.
|
|
|
|
</para>
|
|
|
|
</sect3>
|
1999-02-13 04:42:10 +01:00
|
|
|
|
2000-01-23 02:27:39 +01:00
|
|
|
<sect3>
|
2000-05-02 22:02:03 +02:00
|
|
|
<title>Special values</title>
|
|
|
|
|
2001-05-13 00:51:36 +02:00
|
|
|
<indexterm>
|
|
|
|
<primary>time</primary>
|
|
|
|
<secondary>current</secondary>
|
|
|
|
</indexterm>
|
|
|
|
|
|
|
|
<indexterm>
|
|
|
|
<primary>date</primary>
|
|
|
|
<secondary>current</secondary>
|
|
|
|
</indexterm>
|
|
|
|
|
2000-05-02 22:02:03 +02:00
|
|
|
<para>
|
|
|
|
The following <acronym>SQL</acronym>-compatible functions can be used as date or time
|
2001-02-14 20:37:26 +01:00
|
|
|
input for the corresponding data type: <literal>CURRENT_DATE</literal>,
|
2000-05-02 22:02:03 +02:00
|
|
|
<literal>CURRENT_TIME</literal>, <literal>CURRENT_TIMESTAMP</literal>.
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
<productname>Postgres</productname> also supports several special constants for
|
|
|
|
convenience.
|
2000-01-23 02:27:39 +01:00
|
|
|
|
|
|
|
<table tocentry="1">
|
2001-02-14 20:37:26 +01:00
|
|
|
<title>Special Date/Time Constants</title>
|
2000-01-23 02:27:39 +01:00
|
|
|
<tgroup cols="2">
|
|
|
|
<thead>
|
|
|
|
<row>
|
|
|
|
<entry>Constant</entry>
|
|
|
|
<entry>Description</entry>
|
|
|
|
</row>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
2001-09-28 10:15:35 +02:00
|
|
|
<!--
|
2000-01-23 02:27:39 +01:00
|
|
|
<row>
|
|
|
|
<entry>current</entry>
|
|
|
|
<entry>Current transaction time, deferred</entry>
|
|
|
|
</row>
|
2001-09-28 10:15:35 +02:00
|
|
|
-->
|
2000-01-23 02:27:39 +01:00
|
|
|
<row>
|
|
|
|
<entry>epoch</entry>
|
|
|
|
<entry>1970-01-01 00:00:00+00 (Unix system time zero)</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>infinity</entry>
|
|
|
|
<entry>Later than other valid times</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>-infinity</entry>
|
|
|
|
<entry>Earlier than other valid times</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>invalid</entry>
|
|
|
|
<entry>Illegal entry</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>now</entry>
|
|
|
|
<entry>Current transaction time</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>today</entry>
|
|
|
|
<entry>Midnight today</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>tomorrow</entry>
|
|
|
|
<entry>Midnight tomorrow</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>yesterday</entry>
|
|
|
|
<entry>Midnight yesterday</entry>
|
|
|
|
</row>
|
|
|
|
</tbody>
|
|
|
|
</tgroup>
|
|
|
|
</table>
|
|
|
|
<literal>'now'</literal> is resolved when the value is inserted, <literal>'current'</literal>
|
2001-02-14 20:37:26 +01:00
|
|
|
is resolved every time the value is retrieved. So you probably want to use <literal>'now'</literal>
|
2000-01-23 02:27:39 +01:00
|
|
|
in most applications. (Of course you <emphasis>really</emphasis> want to use
|
|
|
|
<literal>CURRENT_TIMESTAMP</literal>, which is equivalent to <literal>'now'</literal>.)
|
1999-01-19 17:08:26 +01:00
|
|
|
</para>
|
2000-01-23 02:27:39 +01:00
|
|
|
</sect3>
|
1998-12-18 17:11:12 +01:00
|
|
|
|
1999-02-13 04:42:10 +01:00
|
|
|
</sect2>
|
1998-12-18 17:11:12 +01:00
|
|
|
|
2000-01-23 02:27:39 +01:00
|
|
|
|
2001-01-13 19:34:51 +01:00
|
|
|
<sect2 id="datatype-datetime-output">
|
2000-01-23 02:27:39 +01:00
|
|
|
<title>Date/Time Output</title>
|
1999-08-06 15:43:42 +02:00
|
|
|
|
2001-05-13 00:51:36 +02:00
|
|
|
<indexterm>
|
|
|
|
<primary>date</primary>
|
|
|
|
<secondary>output format</secondary>
|
|
|
|
<seealso>Formatting</seealso>
|
|
|
|
</indexterm>
|
|
|
|
|
|
|
|
<indexterm>
|
|
|
|
<primary>time</primary>
|
|
|
|
<secondary>output format</secondary>
|
|
|
|
<seealso>Formatting</seealso>
|
|
|
|
</indexterm>
|
|
|
|
|
1999-08-06 15:43:42 +02:00
|
|
|
<para>
|
2000-01-23 02:27:39 +01:00
|
|
|
Output formats can be set to one of the four styles
|
|
|
|
ISO-8601, <acronym>SQL</acronym> (Ingres), traditional
|
|
|
|
Postgres, and German, using the <command>SET DateStyle</command>.
|
|
|
|
The default is the <acronym>ISO</acronym> format.
|
|
|
|
|
|
|
|
<table tocentry="1">
|
2001-02-14 20:37:26 +01:00
|
|
|
<title>Date/Time Output Styles</title>
|
2000-01-23 02:27:39 +01:00
|
|
|
<tgroup cols="3">
|
|
|
|
<thead>
|
|
|
|
<row>
|
|
|
|
<entry>Style Specification</entry>
|
|
|
|
<entry>Description</entry>
|
|
|
|
<entry>Example</entry>
|
|
|
|
</row>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<row>
|
|
|
|
<entry>'ISO'</entry>
|
|
|
|
<entry>ISO-8601 standard</entry>
|
|
|
|
<entry>1997-12-17 07:37:16-08</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>'SQL'</entry>
|
|
|
|
<entry>Traditional style</entry>
|
|
|
|
<entry>12/17/1997 07:37:16.00 PST</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>'Postgres'</entry>
|
|
|
|
<entry>Original style</entry>
|
|
|
|
<entry>Wed Dec 17 07:37:16 1997 PST</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>'German'</entry>
|
|
|
|
<entry>Regional style</entry>
|
|
|
|
<entry>17.12.1997 07:37:16.00 PST</entry>
|
|
|
|
</row>
|
|
|
|
</tbody>
|
|
|
|
</tgroup>
|
|
|
|
</table>
|
1999-08-06 15:43:42 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2000-01-23 02:27:39 +01:00
|
|
|
The output of the <type>date</type> and <type>time</type> styles is of course
|
2000-05-02 22:02:03 +02:00
|
|
|
only the date or time part in accordance with the above examples.
|
1998-12-18 17:11:12 +01:00
|
|
|
</para>
|
1998-03-01 09:16:16 +01:00
|
|
|
|
1999-08-06 15:43:42 +02:00
|
|
|
<para>
|
2000-01-23 02:27:39 +01:00
|
|
|
The <acronym>SQL</acronym> style has European and non-European (US) variants,
|
2001-02-14 20:37:26 +01:00
|
|
|
which determines whether month follows day or vice versa. (See also above
|
2000-01-23 02:27:39 +01:00
|
|
|
at Date/Time Input, how this setting affects interpretation of input values.)
|
1998-03-01 09:16:16 +01:00
|
|
|
|
2000-01-23 02:27:39 +01:00
|
|
|
<table tocentry="1">
|
2001-02-14 20:37:26 +01:00
|
|
|
<title>Date Order Conventions</title>
|
2000-01-23 02:27:39 +01:00
|
|
|
<tgroup cols="3">
|
|
|
|
<thead>
|
|
|
|
<row>
|
|
|
|
<entry>Style Specification</entry>
|
2000-05-02 22:02:03 +02:00
|
|
|
<entry>Description</entry>
|
2000-01-23 02:27:39 +01:00
|
|
|
<entry>Example</entry>
|
|
|
|
</row>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<row>
|
|
|
|
<entry>European</entry>
|
2000-05-02 22:02:03 +02:00
|
|
|
<entry><replaceable>day</replaceable>/<replaceable>month</replaceable>/<replaceable>year</replaceable></entry>
|
2000-01-23 02:27:39 +01:00
|
|
|
<entry>17/12/1997 15:37:16.00 MET</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>US</entry>
|
2000-05-02 22:02:03 +02:00
|
|
|
<entry><replaceable>month</replaceable>/<replaceable>day</replaceable>/<replaceable>year</replaceable></entry>
|
2000-01-23 02:27:39 +01:00
|
|
|
<entry>12/17/1997 07:37:16.00 PST</entry>
|
|
|
|
</row>
|
|
|
|
</tbody>
|
|
|
|
</tgroup>
|
|
|
|
</table>
|
|
|
|
</para>
|
1998-03-01 09:16:16 +01:00
|
|
|
|
1999-08-06 15:43:42 +02:00
|
|
|
<para>
|
2000-05-02 22:02:03 +02:00
|
|
|
<type>interval</type> output looks like the input format, except that units like
|
2000-01-23 02:27:39 +01:00
|
|
|
<literal>week</literal> or <literal>century</literal> are converted to years and days.
|
|
|
|
In ISO mode the output looks like
|
2000-05-02 22:02:03 +02:00
|
|
|
|
2000-01-23 02:27:39 +01:00
|
|
|
<programlisting>
|
|
|
|
[ Quantity Units [ ... ] ] [ Days ] Hours:Minutes [ ago ]
|
|
|
|
</programlisting>
|
1999-08-06 15:43:42 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2000-01-23 02:27:39 +01:00
|
|
|
There are several ways to affect the appearance of date/time types:
|
1999-08-06 15:43:42 +02:00
|
|
|
|
2000-01-23 02:27:39 +01:00
|
|
|
<itemizedlist spacing="compact" mark="bullet">
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The <envar>PGDATESTYLE</envar> environment variable used by the backend directly
|
2000-08-29 22:02:09 +02:00
|
|
|
on postmaster start-up.
|
2000-01-23 02:27:39 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2001-09-09 19:21:59 +02:00
|
|
|
The <envar>PGDATESTYLE</envar> environment variable used by the frontend <application>libpq</application>
|
2000-08-29 22:02:09 +02:00
|
|
|
on session start-up.
|
2000-01-23 02:27:39 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
<command>SET DATESTYLE</command> <acronym>SQL</acronym> command.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</itemizedlist>
|
1999-08-06 15:43:42 +02:00
|
|
|
</para>
|
2000-01-23 02:27:39 +01:00
|
|
|
|
1999-08-06 15:43:42 +02:00
|
|
|
</sect2>
|
1998-12-18 17:11:12 +01:00
|
|
|
|
2001-01-13 19:34:51 +01:00
|
|
|
<sect2 id="datatype-timezones">
|
2000-01-23 02:27:39 +01:00
|
|
|
<title>Time Zones</title>
|
1998-12-18 17:11:12 +01:00
|
|
|
|
2001-05-13 00:51:36 +02:00
|
|
|
<indexterm zone="datatype-timezones">
|
|
|
|
<primary>time zones</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
1999-08-06 15:43:42 +02:00
|
|
|
<para>
|
2000-05-02 22:02:03 +02:00
|
|
|
<productname>Postgres</productname> endeavors to be compatible with
|
2000-01-23 02:27:39 +01:00
|
|
|
<acronym>SQL92</acronym> definitions for typical usage.
|
|
|
|
However, the <acronym>SQL92</acronym> standard has an odd mix of date and
|
|
|
|
time types and capabilities. Two obvious problems are:
|
1998-03-01 09:16:16 +01:00
|
|
|
|
2000-01-23 02:27:39 +01:00
|
|
|
<itemizedlist>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Although the <type>date</type> type
|
|
|
|
does not have an associated time zone, the
|
|
|
|
<type>time</type> type can or does.
|
2000-11-11 20:50:31 +01:00
|
|
|
Time zones in the real world can have no meaning unless
|
|
|
|
associated with a date as well as a time
|
|
|
|
since the offset may vary through the year with daylight savings
|
|
|
|
time boundaries.
|
2000-01-23 02:27:39 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
1998-03-01 09:16:16 +01:00
|
|
|
|
2000-01-23 02:27:39 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The default time zone is specified as a constant integer offset
|
2000-11-11 20:50:31 +01:00
|
|
|
from GMT/UTC. It is not possible to adapt to daylight savings
|
|
|
|
time when doing date/time arithmetic across
|
|
|
|
<acronym>DST</acronym> boundaries.
|
2000-01-23 02:27:39 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
1998-10-14 18:26:31 +02:00
|
|
|
|
2000-01-23 02:27:39 +01:00
|
|
|
</itemizedlist>
|
1999-08-06 15:43:42 +02:00
|
|
|
</para>
|
|
|
|
|
2000-01-23 02:27:39 +01:00
|
|
|
<para>
|
2000-11-11 20:50:31 +01:00
|
|
|
To address these difficulties, we recommend using date/time
|
2000-12-22 19:57:50 +01:00
|
|
|
types that contain both date and time when using time zones. We
|
2000-11-11 20:50:31 +01:00
|
|
|
recommend <emphasis>not</emphasis> using the SQL92 type TIME
|
|
|
|
WITH TIME ZONE (though it is supported by
|
|
|
|
<productname>Postgres</productname> for legacy applications and
|
|
|
|
for compatibility with other RDBMS implementations).
|
|
|
|
<productname>Postgres</productname>
|
|
|
|
assumes local time for any type containing only
|
2000-01-23 02:27:39 +01:00
|
|
|
date or time. Further, time zone support is derived from
|
|
|
|
the underlying operating system
|
|
|
|
time zone capabilities, and hence can handle daylight savings time
|
|
|
|
and other expected behavior.
|
|
|
|
</para>
|
1999-08-06 15:43:42 +02:00
|
|
|
|
|
|
|
<para>
|
2000-05-02 22:02:03 +02:00
|
|
|
<productname>Postgres</productname> obtains time zone support
|
2000-01-23 02:27:39 +01:00
|
|
|
from the underlying operating system for dates between 1902 and
|
|
|
|
2038 (near the typical date limits for Unix-style
|
|
|
|
systems). Outside of this range, all dates are assumed to be
|
|
|
|
specified and used in Universal Coordinated Time (UTC).
|
1999-08-06 15:43:42 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2000-11-11 20:50:31 +01:00
|
|
|
All dates and times are stored internally in UTC,
|
|
|
|
traditionally known as Greenwich Mean Time (GMT).
|
2000-01-23 02:27:39 +01:00
|
|
|
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.
|
1999-08-06 15:43:42 +02:00
|
|
|
</para>
|
|
|
|
|
2000-01-23 02:27:39 +01:00
|
|
|
<para>
|
|
|
|
There are several ways to affect the time zone behavior:
|
1999-08-06 15:43:42 +02:00
|
|
|
|
2000-01-23 02:27:39 +01:00
|
|
|
<itemizedlist spacing="compact" mark="bullet">
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2001-09-09 19:21:59 +02:00
|
|
|
The <envar>TZ</envar> environment variable is used by the backend directly
|
2000-08-29 22:02:09 +02:00
|
|
|
on postmaster start-up as the default time zone.
|
2000-01-23 02:27:39 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2001-09-09 19:21:59 +02:00
|
|
|
The <envar>PGTZ</envar> environment variable, if set at the client, is used by libpq
|
2001-06-18 21:05:11 +02:00
|
|
|
to send a <command>SET TIME ZONE</command> command to the backend upon
|
|
|
|
connection.
|
2000-01-23 02:27:39 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The <acronym>SQL</acronym> command <command>SET TIME ZONE</command>
|
|
|
|
sets the time zone for the session.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
2000-11-11 20:50:31 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The <acronym>SQL92</acronym> qualifier on
|
|
|
|
<programlisting>
|
|
|
|
<replaceable>timestamp</replaceable> AT TIME ZONE '<replaceable>zone</replaceable>'
|
|
|
|
</programlisting>
|
|
|
|
where <replaceable>zone</replaceable> can be specified as a
|
|
|
|
text time zone (e.g. <literal>'PST'</literal>) or as an
|
|
|
|
interval (e.g. <literal>INTERVAL '-08:00'</literal>).
|
|
|
|
</para>
|
|
|
|
</listitem>
|
2000-01-23 02:27:39 +01:00
|
|
|
</itemizedlist>
|
|
|
|
</para>
|
1999-08-06 15:43:42 +02:00
|
|
|
|
|
|
|
<para>
|
2000-11-11 20:50:31 +01:00
|
|
|
<note>
|
|
|
|
<para>
|
|
|
|
If an invalid time zone is specified,
|
|
|
|
the time zone becomes GMT (on most systems anyway).
|
|
|
|
</para>
|
|
|
|
</note>
|
2000-01-23 02:27:39 +01:00
|
|
|
|
|
|
|
<note>
|
|
|
|
<para>
|
2001-06-18 21:05:11 +02:00
|
|
|
If the runtime option <literal>AUSTRALIAN_TIMEZONES</literal> is set
|
|
|
|
then <literal>CST</literal> and <literal>EST</literal> refer to
|
2001-09-09 19:21:59 +02:00
|
|
|
Australian time zones, not American ones.
|
2000-01-23 02:27:39 +01:00
|
|
|
</para>
|
|
|
|
</note>
|
1999-08-06 15:43:42 +02:00
|
|
|
</para>
|
2000-01-23 02:27:39 +01:00
|
|
|
|
1999-08-06 15:43:42 +02:00
|
|
|
</sect2>
|
|
|
|
|
2001-01-13 19:34:51 +01:00
|
|
|
<sect2 id="datatype-datetime-internals">
|
2000-01-23 02:27:39 +01:00
|
|
|
<title>Internals</title>
|
1999-08-06 15:43:42 +02:00
|
|
|
|
|
|
|
<para>
|
2000-05-02 22:02:03 +02:00
|
|
|
<productname>Postgres</productname> uses Julian dates
|
2000-01-23 02:27:39 +01:00
|
|
|
for all date/time calculations. They have the nice property of correctly
|
|
|
|
predicting/calculating any date more recent than 4713BC
|
|
|
|
to far into the future, using the assumption that the length of the
|
|
|
|
year is 365.2425 days.
|
1999-08-06 15:43:42 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2000-01-23 02:27:39 +01:00
|
|
|
Date conventions before the 19th century make for interesting reading,
|
2001-02-14 20:37:26 +01:00
|
|
|
but are not consistent enough to warrant coding into a date/time handler.
|
1999-08-06 15:43:42 +02:00
|
|
|
</para>
|
|
|
|
</sect2>
|
|
|
|
|
|
|
|
</sect1>
|
|
|
|
|
2001-01-13 19:34:51 +01:00
|
|
|
<sect1 id="datatype-boolean">
|
1999-08-06 15:43:42 +02:00
|
|
|
<title>Boolean Type</title>
|
|
|
|
|
2001-05-13 00:51:36 +02:00
|
|
|
<indexterm zone="datatype-boolean">
|
|
|
|
<primary>Boolean</primary>
|
|
|
|
<secondary>data type</secondary>
|
|
|
|
</indexterm>
|
|
|
|
|
|
|
|
<indexterm zone="datatype-boolean">
|
|
|
|
<primary>true</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
|
|
|
<indexterm zone="datatype-boolean">
|
|
|
|
<primary>false</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
1999-08-06 15:43:42 +02:00
|
|
|
<para>
|
2001-02-14 20:37:26 +01:00
|
|
|
<productname>Postgres</productname> provides the
|
|
|
|
<acronym>SQL99</acronym> type <type>boolean</type>.
|
|
|
|
<type>boolean</type> can have one of only two states:
|
|
|
|
<quote>true</quote> or <quote>false</quote>. A third state,
|
|
|
|
<quote>unknown</quote>, is represented by the
|
|
|
|
<acronym>SQL</acronym> NULL state.
|
2001-01-13 19:34:51 +01:00
|
|
|
</para>
|
1999-08-06 15:43:42 +02:00
|
|
|
|
|
|
|
<para>
|
2001-02-14 20:37:26 +01:00
|
|
|
Valid literal values for the <quote>true</quote> state are:
|
|
|
|
<simplelist>
|
|
|
|
<member><literal>TRUE</literal></member>
|
|
|
|
<member><literal>'t'</literal></member>
|
|
|
|
<member><literal>'true'</literal></member>
|
|
|
|
<member><literal>'y'</literal></member>
|
|
|
|
<member><literal>'yes'</literal></member>
|
|
|
|
<member><literal>'1'</literal></member>
|
|
|
|
</simplelist>
|
|
|
|
For the <quote>false</quote> state, the following values can be
|
|
|
|
used:
|
|
|
|
<simplelist>
|
|
|
|
<member><literal>FALSE</literal></member>
|
|
|
|
<member><literal>'f'</literal></member>
|
|
|
|
<member><literal>'false'</literal></member>
|
|
|
|
<member><literal>'n'</literal></member>
|
|
|
|
<member><literal>'no'</literal></member>
|
|
|
|
<member><literal>'0'</literal></member>
|
|
|
|
</simplelist>
|
|
|
|
Using the key words <literal>TRUE</literal> and
|
|
|
|
<literal>FALSE</literal> is preferred (and
|
|
|
|
<acronym>SQL</acronym>-compliant).
|
1999-08-06 15:43:42 +02:00
|
|
|
</para>
|
|
|
|
|
2001-02-14 20:37:26 +01:00
|
|
|
<example id="datatype-boolean-example">
|
|
|
|
<title>Using the <type>boolean</type> type</title>
|
|
|
|
|
|
|
|
<programlisting>
|
|
|
|
CREATE TABLE test1 (a boolean, b text);
|
|
|
|
INSERT INTO test1 VALUES (TRUE, 'sic est');
|
|
|
|
INSERT INTO test1 VALUES (FALSE, 'non est');
|
|
|
|
SELECT * FROM test1;
|
|
|
|
a | b
|
|
|
|
---+---------
|
|
|
|
t | sic est
|
|
|
|
f | non est
|
|
|
|
|
|
|
|
SELECT * FROM test1 WHERE a;
|
|
|
|
a | b
|
|
|
|
---+---------
|
|
|
|
t | sic est
|
|
|
|
</programlisting>
|
|
|
|
</example>
|
|
|
|
|
1999-08-06 15:43:42 +02:00
|
|
|
<para>
|
2001-02-14 20:37:26 +01:00
|
|
|
<xref linkend="datatype-boolean-example"> shows that
|
|
|
|
<type>boolean</type> values are output using the letters
|
|
|
|
<literal>t</literal> and <literal>f</literal>.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<tip>
|
|
|
|
<para>
|
|
|
|
Values of the <type>boolean</type> type cannot be cast directly
|
|
|
|
to other types (e.g., <literal>CAST
|
|
|
|
(<replaceable>boolval</replaceable> AS integer)</literal> does
|
|
|
|
not work). This can be accomplished using the
|
|
|
|
<literal>CASE</literal> expression: <literal>CASE WHEN
|
|
|
|
<replaceable>boolval</replaceable> THEN 'value if true' ELSE
|
|
|
|
'value if false' END</literal>. See also <xref
|
|
|
|
linkend="functions-conditional">.
|
|
|
|
</para>
|
|
|
|
</tip>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
<type>boolean</type> uses 1 byte of storage.
|
1999-08-06 15:43:42 +02:00
|
|
|
</para>
|
|
|
|
</sect1>
|
|
|
|
|
2001-01-13 19:34:51 +01:00
|
|
|
<sect1 id="datatype-geometric">
|
1999-08-06 15:43:42 +02:00
|
|
|
<title>Geometric Types</title>
|
|
|
|
|
|
|
|
<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">
|
2001-02-14 20:37:26 +01:00
|
|
|
<title>Geometric Types</title>
|
1999-08-06 15:43:42 +02:00
|
|
|
<tgroup cols="4">
|
|
|
|
<thead>
|
|
|
|
<row>
|
|
|
|
<entry>Geometric Type</entry>
|
|
|
|
<entry>Storage</entry>
|
|
|
|
<entry>Representation</entry>
|
|
|
|
<entry>Description</entry>
|
|
|
|
</row>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<row>
|
2001-09-09 19:21:59 +02:00
|
|
|
<entry><type>point</type></entry>
|
1999-08-06 15:43:42 +02:00
|
|
|
<entry>16 bytes</entry>
|
|
|
|
<entry>(x,y)</entry>
|
|
|
|
<entry>Point in space</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
2001-09-09 19:21:59 +02:00
|
|
|
<entry><type>line</type></entry>
|
1999-08-06 15:43:42 +02:00
|
|
|
<entry>32 bytes</entry>
|
|
|
|
<entry>((x1,y1),(x2,y2))</entry>
|
|
|
|
<entry>Infinite line</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
2001-09-09 19:21:59 +02:00
|
|
|
<entry><type>lseg</type></entry>
|
1999-08-06 15:43:42 +02:00
|
|
|
<entry>32 bytes</entry>
|
|
|
|
<entry>((x1,y1),(x2,y2))</entry>
|
|
|
|
<entry>Finite line segment</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
2001-09-09 19:21:59 +02:00
|
|
|
<entry><type>box</type></entry>
|
1999-08-06 15:43:42 +02:00
|
|
|
<entry>32 bytes</entry>
|
|
|
|
<entry>((x1,y1),(x2,y2))</entry>
|
|
|
|
<entry>Rectangular box</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
2001-09-09 19:21:59 +02:00
|
|
|
<entry><type>path</type></entry>
|
1999-08-06 15:43:42 +02:00
|
|
|
<entry>4+32n bytes</entry>
|
|
|
|
<entry>((x1,y1),...)</entry>
|
|
|
|
<entry>Closed path (similar to polygon)</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
2001-09-09 19:21:59 +02:00
|
|
|
<entry><type>path</type></entry>
|
1999-08-06 15:43:42 +02:00
|
|
|
<entry>4+32n bytes</entry>
|
|
|
|
<entry>[(x1,y1),...]</entry>
|
|
|
|
<entry>Open path</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
2001-09-09 19:21:59 +02:00
|
|
|
<entry><type>polygon</type></entry>
|
1999-08-06 15:43:42 +02:00
|
|
|
<entry>4+32n bytes</entry>
|
|
|
|
<entry>((x1,y1),...)</entry>
|
|
|
|
<entry>Polygon (similar to closed path)</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
2001-09-09 19:21:59 +02:00
|
|
|
<entry><type>circle</type></entry>
|
1999-08-06 15:43:42 +02:00
|
|
|
<entry>24 bytes</entry>
|
|
|
|
<entry><(x,y),r></entry>
|
|
|
|
<entry>Circle (center and radius)</entry>
|
|
|
|
</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>
|
|
|
|
|
|
|
|
<sect2>
|
|
|
|
<title>Point</title>
|
1998-03-01 09:16:16 +01:00
|
|
|
|
2001-05-13 00:51:36 +02:00
|
|
|
<indexterm>
|
|
|
|
<primary>point</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
1998-12-18 17:11:12 +01:00
|
|
|
<para>
|
|
|
|
Points are the fundamental two-dimensional building block for geometric types.
|
|
|
|
</para>
|
|
|
|
|
1999-08-06 15:43:42 +02:00
|
|
|
<para>
|
|
|
|
<type>point</type> is specified using the following syntax:
|
1998-03-01 09:16:16 +01:00
|
|
|
|
2000-05-02 22:02:03 +02:00
|
|
|
<synopsis>
|
|
|
|
( <replaceable>x</replaceable> , <replaceable>y</replaceable> )
|
|
|
|
<replaceable>x</replaceable> , <replaceable>y</replaceable>
|
|
|
|
</synopsis>
|
|
|
|
|
|
|
|
where the arguments are
|
|
|
|
|
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
|
|
|
<term><replaceable>x</replaceable></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The x-axis coordinate as a floating point number.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><replaceable>y</replaceable></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The y-axis coordinate as a floating point number.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
1999-08-06 15:43:42 +02:00
|
|
|
</para>
|
|
|
|
</sect2>
|
1998-03-01 09:16:16 +01:00
|
|
|
|
1999-08-06 15:43:42 +02:00
|
|
|
<sect2>
|
|
|
|
<title>Line Segment</title>
|
1998-03-01 09:16:16 +01:00
|
|
|
|
2001-05-13 00:51:36 +02:00
|
|
|
<indexterm>
|
|
|
|
<primary>line</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
1999-08-06 15:43:42 +02:00
|
|
|
<para>
|
|
|
|
Line segments (<type>lseg</type>) are represented by pairs of points.
|
|
|
|
</para>
|
1998-03-01 09:16:16 +01:00
|
|
|
|
1999-08-06 15:43:42 +02:00
|
|
|
<para>
|
|
|
|
<type>lseg</type> is specified using the following syntax:
|
2000-05-02 22:02:03 +02:00
|
|
|
|
|
|
|
<synopsis>
|
|
|
|
( ( <replaceable>x1</replaceable> , <replaceable>y1</replaceable> ) , ( <replaceable>x2</replaceable> , <replaceable>y2</replaceable> ) )
|
|
|
|
( <replaceable>x1</replaceable> , <replaceable>y1</replaceable> ) , ( <replaceable>x2</replaceable> , <replaceable>y2</replaceable> )
|
|
|
|
<replaceable>x1</replaceable> , <replaceable>y1</replaceable> , <replaceable>x2</replaceable> , <replaceable>y2</replaceable>
|
|
|
|
</synopsis>
|
|
|
|
|
|
|
|
where the arguments are
|
|
|
|
|
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
|
|
|
<term>(<replaceable>x1</replaceable>,<replaceable>y1</replaceable>)</term>
|
|
|
|
<term>(<replaceable>x2</replaceable>,<replaceable>y2</replaceable>)</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2001-02-14 20:37:26 +01:00
|
|
|
The end points of the line segment.
|
2000-05-02 22:02:03 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
1999-08-06 15:43:42 +02:00
|
|
|
</para>
|
|
|
|
</sect2>
|
1998-03-01 09:16:16 +01:00
|
|
|
|
1999-08-06 15:43:42 +02:00
|
|
|
<sect2>
|
|
|
|
<title>Box</title>
|
1998-03-01 09:16:16 +01:00
|
|
|
|
2001-05-13 00:51:36 +02:00
|
|
|
<indexterm>
|
|
|
|
<primary>box (data type)</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
1999-08-06 15:43:42 +02:00
|
|
|
<para>
|
2000-12-22 19:57:50 +01:00
|
|
|
Boxes are represented by pairs of points that are opposite
|
1999-08-06 15:43:42 +02:00
|
|
|
corners of the box.
|
|
|
|
</para>
|
1998-03-01 09:16:16 +01:00
|
|
|
|
1999-08-06 15:43:42 +02:00
|
|
|
<para>
|
1998-12-18 17:11:12 +01:00
|
|
|
<type>box</type> is specified using the following syntax:
|
1998-03-01 09:16:16 +01:00
|
|
|
|
2000-05-02 22:02:03 +02:00
|
|
|
<synopsis>
|
|
|
|
( ( <replaceable>x1</replaceable> , <replaceable>y1</replaceable> ) , ( <replaceable>x2</replaceable> , <replaceable>y2</replaceable> ) )
|
|
|
|
( <replaceable>x1</replaceable> , <replaceable>y1</replaceable> ) , ( <replaceable>x2</replaceable> , <replaceable>y2</replaceable> )
|
|
|
|
<replaceable>x1</replaceable> , <replaceable>y1</replaceable> , <replaceable>x2</replaceable> , <replaceable>y2</replaceable>
|
|
|
|
</synopsis>
|
|
|
|
|
|
|
|
where the arguments are
|
|
|
|
|
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
|
|
|
<term>(<replaceable>x1</replaceable>,<replaceable>y1</replaceable>)</term>
|
|
|
|
<term>(<replaceable>x2</replaceable>,<replaceable>y2</replaceable>)</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Opposite corners of the box.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
|
|
|
</para>
|
1999-08-06 15:43:42 +02:00
|
|
|
|
2000-05-02 22:02:03 +02:00
|
|
|
<para>
|
1999-08-06 15:43:42 +02:00
|
|
|
Boxes are output using the first syntax.
|
|
|
|
The corners are reordered on input to store
|
2001-03-10 22:16:32 +01:00
|
|
|
the upper right corner, then the lower left corner.
|
1999-08-06 15:43:42 +02:00
|
|
|
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>
|
|
|
|
|
|
|
|
<sect2>
|
|
|
|
<title>Path</title>
|
|
|
|
|
2001-05-13 00:51:36 +02:00
|
|
|
<indexterm>
|
|
|
|
<primary>path (data type)</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
1999-08-06 15:43:42 +02:00
|
|
|
<para>
|
2001-09-13 17:55:24 +02:00
|
|
|
Paths are represented by connected sets of points. Paths can be
|
|
|
|
<firstterm>open</firstterm>, where
|
|
|
|
the first and last points in the set are not connected, and <firstterm>closed</firstterm>,
|
1999-08-06 15:43:42 +02:00
|
|
|
where the first and last point are connected. Functions
|
|
|
|
<function>popen(p)</function>
|
|
|
|
and
|
|
|
|
<function>pclose(p)</function>
|
|
|
|
are supplied to force a path to be open or closed, and functions
|
|
|
|
<function>isopen(p)</function>
|
|
|
|
and
|
|
|
|
<function>isclosed(p)</function>
|
2000-05-02 22:02:03 +02:00
|
|
|
are supplied to test for either type in a query.
|
1999-08-06 15:43:42 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
<type>path</type> is specified using the following syntax:
|
|
|
|
|
2000-05-02 22:02:03 +02:00
|
|
|
<synopsis>
|
|
|
|
( ( <replaceable>x1</replaceable> , <replaceable>y1</replaceable> ) , ... , ( <replaceable>xn</replaceable> , <replaceable>yn</replaceable> ) )
|
|
|
|
[ ( <replaceable>x1</replaceable> , <replaceable>y1</replaceable> ) , ... , ( <replaceable>xn</replaceable> , <replaceable>yn</replaceable> ) ]
|
|
|
|
( <replaceable>x1</replaceable> , <replaceable>y1</replaceable> ) , ... , ( <replaceable>xn</replaceable> , <replaceable>yn</replaceable> )
|
|
|
|
( <replaceable>x1</replaceable> , <replaceable>y1</replaceable> , ... , <replaceable>xn</replaceable> , <replaceable>yn</replaceable> )
|
|
|
|
<replaceable>x1</replaceable> , <replaceable>y1</replaceable> , ... , <replaceable>xn</replaceable> , <replaceable>yn</replaceable>
|
|
|
|
</synopsis>
|
|
|
|
|
|
|
|
where the arguments are
|
|
|
|
|
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
|
|
|
<term>(<replaceable>x</replaceable>,<replaceable>y</replaceable>)</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2001-02-14 20:37:26 +01:00
|
|
|
End points of the line segments comprising the path.
|
2000-05-02 22:02:03 +02:00
|
|
|
A leading square bracket ("[") indicates an open path, while
|
|
|
|
a leading parenthesis ("(") indicates a closed path.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
|
|
|
</para>
|
1999-08-06 15:43:42 +02:00
|
|
|
|
2000-05-02 22:02:03 +02:00
|
|
|
<para>
|
1999-08-06 15:43:42 +02:00
|
|
|
Paths are output using the first syntax.
|
|
|
|
</para>
|
|
|
|
</sect2>
|
|
|
|
|
|
|
|
<sect2>
|
|
|
|
<title>Polygon</title>
|
|
|
|
|
2001-05-13 00:51:36 +02:00
|
|
|
<indexterm>
|
|
|
|
<primary>polygon</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
1999-08-06 15:43:42 +02:00
|
|
|
<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>
|
|
|
|
<type>polygon</type> is specified using the following syntax:
|
|
|
|
|
2000-05-02 22:02:03 +02:00
|
|
|
<synopsis>
|
|
|
|
( ( <replaceable>x1</replaceable> , <replaceable>y1</replaceable> ) , ... , ( <replaceable>xn</replaceable> , <replaceable>yn</replaceable> ) )
|
|
|
|
( <replaceable>x1</replaceable> , <replaceable>y1</replaceable> ) , ... , ( <replaceable>xn</replaceable> , <replaceable>yn</replaceable> )
|
|
|
|
( <replaceable>x1</replaceable> , <replaceable>y1</replaceable> , ... , <replaceable>xn</replaceable> , <replaceable>yn</replaceable> )
|
|
|
|
<replaceable>x1</replaceable> , <replaceable>y1</replaceable> , ... , <replaceable>xn</replaceable> , <replaceable>yn</replaceable>
|
|
|
|
</synopsis>
|
|
|
|
|
|
|
|
where the arguments are
|
|
|
|
|
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
|
|
|
<term>(<replaceable>x</replaceable>,<replaceable>y</replaceable>)</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2001-02-14 20:37:26 +01:00
|
|
|
End points of the line segments comprising the boundary of the
|
2000-05-02 22:02:03 +02:00
|
|
|
polygon.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
|
|
|
</para>
|
1999-08-06 15:43:42 +02:00
|
|
|
|
2000-05-02 22:02:03 +02:00
|
|
|
<para>
|
1999-08-06 15:43:42 +02:00
|
|
|
Polygons are output using the first syntax.
|
|
|
|
</para>
|
|
|
|
</sect2>
|
1998-03-01 09:16:16 +01:00
|
|
|
|
1999-08-06 15:43:42 +02:00
|
|
|
<sect2>
|
|
|
|
<title>Circle</title>
|
1998-03-01 09:16:16 +01:00
|
|
|
|
2001-05-13 00:51:36 +02:00
|
|
|
<indexterm>
|
|
|
|
<primary>circle</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
1999-08-06 15:43:42 +02:00
|
|
|
<para>
|
|
|
|
Circles are represented by a center point and a radius.
|
|
|
|
</para>
|
1998-03-01 09:16:16 +01:00
|
|
|
|
1999-08-06 15:43:42 +02:00
|
|
|
<para>
|
|
|
|
<type>circle</type> is specified using the following syntax:
|
1998-03-01 09:16:16 +01:00
|
|
|
|
2000-05-02 22:02:03 +02:00
|
|
|
<synopsis>
|
|
|
|
< ( <replaceable>x</replaceable> , <replaceable>y</replaceable> ) , <replaceable>r</replaceable> >
|
|
|
|
( ( <replaceable>x</replaceable> , <replaceable>y</replaceable> ) , <replaceable>r</replaceable> )
|
|
|
|
( <replaceable>x</replaceable> , <replaceable>y</replaceable> ) , <replaceable>r</replaceable>
|
|
|
|
<replaceable>x</replaceable> , <replaceable>y</replaceable> , <replaceable>r</replaceable>
|
|
|
|
</synopsis>
|
|
|
|
|
|
|
|
where the arguments are
|
|
|
|
|
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
|
|
|
<term>(<replaceable>x</replaceable>,<replaceable>y</replaceable>)</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Center of the circle.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><replaceable>r</replaceable></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Radius of the circle.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
|
|
|
</para>
|
1999-08-06 15:43:42 +02:00
|
|
|
|
2000-05-02 22:02:03 +02:00
|
|
|
<para>
|
1999-08-06 15:43:42 +02:00
|
|
|
Circles are output using the first syntax.
|
|
|
|
</para>
|
|
|
|
</sect2>
|
|
|
|
|
|
|
|
</sect1>
|
|
|
|
|
2001-01-13 19:34:51 +01:00
|
|
|
<sect1 id="datatype-net-types">
|
2000-10-04 17:47:45 +02:00
|
|
|
<title>Network Address Data Types</title>
|
1999-08-06 15:43:42 +02:00
|
|
|
|
2001-05-13 00:51:36 +02:00
|
|
|
<indexterm zone="datatype-net-types">
|
|
|
|
<primary>network</primary>
|
|
|
|
<secondary>addresses</secondary>
|
|
|
|
</indexterm>
|
|
|
|
|
1999-08-06 15:43:42 +02:00
|
|
|
<para>
|
2000-10-04 17:47:45 +02:00
|
|
|
<productname>Postgres</> offers data types to store IP and MAC
|
2000-11-10 21:13:27 +01:00
|
|
|
addresses. It is preferable to use these types over plain text
|
2000-10-04 17:47:45 +02:00
|
|
|
types, because these types offer input error checking and several
|
|
|
|
specialized operators and functions.
|
1999-08-06 15:43:42 +02:00
|
|
|
|
2001-01-13 19:34:51 +01:00
|
|
|
<table tocentry="1" id="datatype-net-types-table">
|
2000-10-04 17:47:45 +02:00
|
|
|
<title>Network Address Data Types</title>
|
1999-08-06 15:43:42 +02:00
|
|
|
<tgroup cols="4">
|
|
|
|
<thead>
|
|
|
|
<row>
|
2000-10-04 17:47:45 +02:00
|
|
|
<entry>Name</entry>
|
1999-08-06 15:43:42 +02:00
|
|
|
<entry>Storage</entry>
|
|
|
|
<entry>Description</entry>
|
|
|
|
<entry>Range</entry>
|
|
|
|
</row>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
2000-10-04 17:47:45 +02:00
|
|
|
|
1999-08-06 15:43:42 +02:00
|
|
|
<row>
|
2001-09-09 19:21:59 +02:00
|
|
|
<entry><type>cidr</type></entry>
|
2000-11-10 21:13:27 +01:00
|
|
|
<entry>12 bytes</entry>
|
2000-10-04 17:47:45 +02:00
|
|
|
<entry>IP networks</entry>
|
|
|
|
<entry>valid IPv4 networks</entry>
|
1999-08-06 15:43:42 +02:00
|
|
|
</row>
|
2000-10-04 17:47:45 +02:00
|
|
|
|
1999-08-06 15:43:42 +02:00
|
|
|
<row>
|
2001-09-09 19:21:59 +02:00
|
|
|
<entry><type>inet</type></entry>
|
2000-11-10 21:13:27 +01:00
|
|
|
<entry>12 bytes</entry>
|
2000-10-04 17:47:45 +02:00
|
|
|
<entry>IP hosts and networks</entry>
|
2000-11-10 21:13:27 +01:00
|
|
|
<entry>valid IPv4 hosts or networks</entry>
|
1999-08-06 15:43:42 +02:00
|
|
|
</row>
|
2000-10-04 17:47:45 +02:00
|
|
|
|
|
|
|
<row>
|
2001-09-09 19:21:59 +02:00
|
|
|
<entry><type>macaddr</type></entry>
|
2000-10-04 17:47:45 +02:00
|
|
|
<entry>6 bytes</entry>
|
|
|
|
<entry>MAC addresses</entry>
|
|
|
|
<entry>customary formats</entry>
|
|
|
|
</row>
|
|
|
|
|
1999-08-06 15:43:42 +02:00
|
|
|
</tbody>
|
|
|
|
</tgroup>
|
|
|
|
</table>
|
|
|
|
</para>
|
|
|
|
|
2000-10-04 17:47:45 +02:00
|
|
|
<para>
|
|
|
|
IP v6 is not supported, yet.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
|
2001-01-13 19:34:51 +01:00
|
|
|
<sect2 id="datatype-inet">
|
2000-11-10 21:13:27 +01:00
|
|
|
<title><type>inet</type></title>
|
|
|
|
|
2001-05-13 00:51:36 +02:00
|
|
|
<indexterm>
|
|
|
|
<primary>inet (data type)</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
2000-11-10 21:13:27 +01:00
|
|
|
<para>
|
|
|
|
The <type>inet</type> type holds an IP host address, and
|
|
|
|
optionally the identity of the subnet it is in, all in one field.
|
|
|
|
The subnet identity is represented by the number of bits in the
|
2001-02-14 20:37:26 +01:00
|
|
|
network part of the address (the <quote>netmask</quote>). If the netmask is 32,
|
2000-11-10 21:13:27 +01:00
|
|
|
then the value does not indicate a subnet, only a single host.
|
|
|
|
Note that if you want to accept networks only, you should use the
|
|
|
|
<type>cidr</type> type rather than <type>inet</type>.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
The input format for this type is <replaceable
|
|
|
|
class="parameter">x.x.x.x/y</replaceable> where <replaceable
|
|
|
|
class="parameter">x.x.x.x</replaceable> is an IP address and
|
|
|
|
<replaceable class="parameter">y</replaceable> is the number of
|
|
|
|
bits in the netmask. If the <replaceable
|
2000-12-22 19:00:24 +01:00
|
|
|
class="parameter">/y</replaceable> part is left off, then the
|
2000-11-10 21:13:27 +01:00
|
|
|
netmask is 32, and the value represents just a single host.
|
|
|
|
On display, the <replaceable class="parameter">/y</replaceable>
|
|
|
|
portion is suppressed if the netmask is 32.
|
|
|
|
</para>
|
|
|
|
</sect2>
|
|
|
|
|
2001-01-13 19:34:51 +01:00
|
|
|
<sect2 id="datatype-cidr">
|
2000-10-04 17:47:45 +02:00
|
|
|
<title><type>cidr</></title>
|
1999-08-06 15:43:42 +02:00
|
|
|
|
2001-05-13 00:51:36 +02:00
|
|
|
<indexterm>
|
|
|
|
<primary>cidr</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
1999-08-06 15:43:42 +02:00
|
|
|
<para>
|
2000-11-10 21:13:27 +01:00
|
|
|
The <type>cidr</type> type holds an IP network specification.
|
|
|
|
Input and output formats follow Classless Internet Domain Routing
|
|
|
|
conventions.
|
|
|
|
The format for
|
2000-10-04 17:47:45 +02:00
|
|
|
specifying classless networks is <replaceable
|
|
|
|
class="parameter">x.x.x.x/y</> where <replaceable
|
|
|
|
class="parameter">x.x.x.x</> is the network and <replaceable
|
|
|
|
class="parameter">y</> is the number of bits in the netmask. If
|
2000-12-22 19:00:24 +01:00
|
|
|
<replaceable class="parameter">y</> is omitted, it is calculated
|
2000-11-10 21:13:27 +01:00
|
|
|
using assumptions from the older classful numbering system, except
|
|
|
|
that it will be at least large enough to include all of the octets
|
|
|
|
written in the input.
|
1999-08-06 15:43:42 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Here are some examples:
|
1998-10-27 07:14:41 +01:00
|
|
|
|
1998-12-18 17:11:12 +01:00
|
|
|
<table tocentry="1">
|
2000-10-04 17:47:45 +02:00
|
|
|
<title><type>cidr</> Type Input Examples</title>
|
2000-12-22 19:00:24 +01:00
|
|
|
<tgroup cols="3">
|
1998-12-18 17:11:12 +01:00
|
|
|
<thead>
|
|
|
|
<row>
|
2001-09-09 19:21:59 +02:00
|
|
|
<entry><type>CIDR</type> Input</entry>
|
|
|
|
<entry><type>CIDR</type> Displayed</entry>
|
|
|
|
<entry><function>abbrev</function>(<type>CIDR</type>)</entry>
|
1998-12-18 17:11:12 +01:00
|
|
|
</row>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
2000-10-04 17:47:45 +02:00
|
|
|
<row>
|
|
|
|
<entry>192.168.100.128/25</entry>
|
|
|
|
<entry>192.168.100.128/25</entry>
|
2000-12-22 19:00:24 +01:00
|
|
|
<entry>192.168.100.128/25</entry>
|
2000-10-04 17:47:45 +02:00
|
|
|
</row>
|
2000-11-10 21:13:27 +01:00
|
|
|
<row>
|
|
|
|
<entry>192.168/24</entry>
|
2000-12-22 19:00:24 +01:00
|
|
|
<entry>192.168.0.0/24</entry>
|
2000-11-10 21:13:27 +01:00
|
|
|
<entry>192.168.0/24</entry>
|
|
|
|
</row>
|
2000-10-04 17:47:45 +02:00
|
|
|
<row>
|
|
|
|
<entry>192.168/25</entry>
|
|
|
|
<entry>192.168.0.0/25</entry>
|
2000-12-22 19:00:24 +01:00
|
|
|
<entry>192.168.0.0/25</entry>
|
2000-10-04 17:47:45 +02:00
|
|
|
</row>
|
1998-12-18 17:11:12 +01:00
|
|
|
<row>
|
|
|
|
<entry>192.168.1</entry>
|
2000-12-22 19:00:24 +01:00
|
|
|
<entry>192.168.1.0/24</entry>
|
1998-12-18 17:11:12 +01:00
|
|
|
<entry>192.168.1/24</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>192.168</entry>
|
2000-12-22 19:00:24 +01:00
|
|
|
<entry>192.168.0.0/24</entry>
|
1998-12-18 17:11:12 +01:00
|
|
|
<entry>192.168.0/24</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>128.1</entry>
|
2000-12-22 19:00:24 +01:00
|
|
|
<entry>128.1.0.0/16</entry>
|
1998-12-18 17:11:12 +01:00
|
|
|
<entry>128.1/16</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>128</entry>
|
2000-12-22 19:00:24 +01:00
|
|
|
<entry>128.0.0.0/16</entry>
|
1998-12-18 17:11:12 +01:00
|
|
|
<entry>128.0/16</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>128.1.2</entry>
|
2000-12-22 19:00:24 +01:00
|
|
|
<entry>128.1.2.0/24</entry>
|
1998-12-18 17:11:12 +01:00
|
|
|
<entry>128.1.2/24</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>10.1.2</entry>
|
2000-12-22 19:00:24 +01:00
|
|
|
<entry>10.1.2.0/24</entry>
|
1998-12-18 17:11:12 +01:00
|
|
|
<entry>10.1.2/24</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>10.1</entry>
|
2000-12-22 19:00:24 +01:00
|
|
|
<entry>10.1.0.0/16</entry>
|
1998-12-18 17:11:12 +01:00
|
|
|
<entry>10.1/16</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>10</entry>
|
2000-12-22 19:00:24 +01:00
|
|
|
<entry>10.0.0.0/8</entry>
|
1998-12-18 17:11:12 +01:00
|
|
|
<entry>10/8</entry>
|
|
|
|
</row>
|
|
|
|
</tbody>
|
|
|
|
</tgroup>
|
|
|
|
</table>
|
|
|
|
</para>
|
2000-11-11 20:50:31 +01:00
|
|
|
</sect2>
|
|
|
|
|
2001-01-13 19:34:51 +01:00
|
|
|
<sect2 id="datatype-inet-vs-cidr">
|
2000-11-12 00:27:48 +01:00
|
|
|
<title><type>inet</type> vs <type>cidr</type></title>
|
1998-12-18 17:11:12 +01:00
|
|
|
|
1999-08-06 15:43:42 +02:00
|
|
|
<para>
|
2000-11-10 21:13:27 +01:00
|
|
|
The essential difference between <type>inet</type> and <type>cidr</type>
|
|
|
|
data types is that <type>inet</type> accepts values with nonzero bits to
|
|
|
|
the right of the netmask, whereas <type>cidr</type> does not.
|
|
|
|
|
|
|
|
<tip>
|
|
|
|
<para>
|
|
|
|
If you do not like the output format for <type>inet</type> or
|
2000-12-22 19:00:24 +01:00
|
|
|
<type>cidr</type> values, try the <function>host</>(),
|
|
|
|
<function>text</>(), and <function>abbrev</>() functions.
|
2000-11-10 21:13:27 +01:00
|
|
|
</para>
|
|
|
|
</tip>
|
1999-08-06 15:43:42 +02:00
|
|
|
</para>
|
|
|
|
</sect2>
|
2000-10-04 17:47:45 +02:00
|
|
|
|
2001-01-13 19:34:51 +01:00
|
|
|
<sect2 id="datatype-macaddr">
|
2000-10-04 17:47:45 +02:00
|
|
|
<title><type>macaddr</></>
|
|
|
|
|
2001-05-13 00:51:36 +02:00
|
|
|
<indexterm>
|
|
|
|
<primary>macaddr (data type)</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
|
|
|
<indexterm>
|
|
|
|
<primary>MAC address</primary>
|
|
|
|
<see>macaddr</see>
|
|
|
|
</indexterm>
|
|
|
|
|
2000-10-04 17:47:45 +02:00
|
|
|
<para>
|
|
|
|
The <type>macaddr</> type stores MAC addresses, i.e., Ethernet
|
|
|
|
card hardware addresses (although MAC addresses are used for
|
|
|
|
other purposes as well). Input is accepted in various customary
|
2001-10-09 20:46:00 +02:00
|
|
|
formats, including
|
|
|
|
|
|
|
|
<simplelist>
|
|
|
|
<member><literal>'08002b:010203'</></member>
|
|
|
|
<member><literal>'08002b-010203'</></member>
|
|
|
|
<member><literal>'0800.2b01.0203'</></member>
|
|
|
|
<member><literal>'08-00-2b-01-02-03'</></member>
|
|
|
|
<member><literal>'08:00:2b:01:02:03'</></member>
|
|
|
|
</simplelist>
|
|
|
|
|
|
|
|
which would all specify the same
|
2000-10-04 17:47:45 +02:00
|
|
|
address. Upper and lower case is accepted for the digits
|
|
|
|
<literal>a</> through <literal>f</>. Output is always in the
|
2001-10-09 20:46:00 +02:00
|
|
|
last of the shown forms.
|
2000-10-04 17:47:45 +02:00
|
|
|
</para>
|
2001-02-10 19:02:35 +01:00
|
|
|
|
|
|
|
<para>
|
|
|
|
The directory <filename class="directory">contrib/mac</filename>
|
2001-10-09 20:46:00 +02:00
|
|
|
in the <productname>PostgreSQL</productname> source distribution
|
2001-02-10 19:02:35 +01:00
|
|
|
contains tools that can be used to map MAC addresses to hardware
|
|
|
|
manufacturer names.
|
|
|
|
</para>
|
2000-10-04 17:47:45 +02:00
|
|
|
</sect2>
|
|
|
|
|
1999-08-06 15:43:42 +02:00
|
|
|
</sect1>
|
|
|
|
|
2001-01-13 19:34:51 +01:00
|
|
|
<sect1 id="datatype-bit">
|
|
|
|
<title>Bit String Types</title>
|
|
|
|
|
2001-05-13 00:51:36 +02:00
|
|
|
<indexterm zone="datatype-bit">
|
|
|
|
<primary>bit strings</primary>
|
|
|
|
<secondary>data type</secondary>
|
|
|
|
</indexterm>
|
|
|
|
|
2001-01-13 19:34:51 +01:00
|
|
|
<para>
|
|
|
|
Bit strings are strings of 1's and 0's. They can be used to store
|
|
|
|
or visualize bit masks. There are two SQL bit types:
|
|
|
|
<type>BIT(<replaceable>x</replaceable>)</type> and <type>BIT
|
2001-05-22 18:37:17 +02:00
|
|
|
VARYING(<replaceable>x</replaceable>)</type>; where
|
|
|
|
<replaceable>x</replaceable> is a positive integer.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
<type>BIT</type> type data must match the length
|
|
|
|
<replaceable>x</replaceable> exactly; it is an error to attempt to
|
|
|
|
store shorter or longer bit strings. <type>BIT VARYING</type> is
|
|
|
|
of variable length up to the maximum length
|
|
|
|
<replaceable>x</replaceable>; longer strings will be rejected.
|
|
|
|
<type>BIT</type> without length is equivalent to
|
|
|
|
<literal>BIT(1)</literal>, <type>BIT VARYING</type> without length
|
|
|
|
specification means unlimited length.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<note>
|
|
|
|
<para>
|
|
|
|
Prior to PostgreSQL 7.2, <type>BIT</type> type data was
|
|
|
|
zero-padded on the right. This was changed to comply with the
|
|
|
|
SQL standard. To implement zero-padded bit strings, a
|
|
|
|
combination of the concatenation operator and the
|
|
|
|
<function>substring</function> function can be used.
|
|
|
|
</para>
|
|
|
|
</note>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Refer to <xref
|
2001-01-13 19:34:51 +01:00
|
|
|
linkend="sql-syntax-bit-strings"> for information about the syntax
|
|
|
|
of bit string constants. Bit-logical operators and string
|
|
|
|
manipulation functions are available; see <xref
|
|
|
|
linkend="functions">.
|
|
|
|
</para>
|
|
|
|
|
2001-05-22 18:37:17 +02:00
|
|
|
<example>
|
|
|
|
<title>Using the bit string types</title>
|
|
|
|
|
2001-01-13 19:34:51 +01:00
|
|
|
<programlisting>
|
|
|
|
CREATE TABLE test (a BIT(3), b BIT VARYING(5));
|
|
|
|
INSERT INTO test VALUES (B'101', B'00');
|
2001-05-22 18:37:17 +02:00
|
|
|
INSERT INTO test VALUES (B'10', B'101');
|
|
|
|
<computeroutput>
|
|
|
|
ERROR: bit string length does not match type bit(3)
|
|
|
|
</computeroutput>
|
2001-01-13 19:34:51 +01:00
|
|
|
SELECT SUBSTRING(b FROM 1 FOR 2) FROM test;
|
|
|
|
</programlisting>
|
2001-05-22 18:37:17 +02:00
|
|
|
</example>
|
2001-01-13 19:34:51 +01:00
|
|
|
|
|
|
|
</sect1>
|
|
|
|
|
1999-08-06 15:43:42 +02:00
|
|
|
</chapter>
|
1998-12-18 17:11:12 +01:00
|
|
|
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
|
|
Local variables:
|
2000-03-31 05:27:42 +02:00
|
|
|
mode:sgml
|
1999-02-13 04:42:10 +01:00
|
|
|
sgml-omittag:nil
|
1998-12-18 17:11:12 +01:00
|
|
|
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
|
2000-03-31 05:27:42 +02:00
|
|
|
sgml-local-catalogs:("/usr/lib/sgml/catalog")
|
1998-12-18 17:11:12 +01:00
|
|
|
sgml-local-ecat-files:nil
|
|
|
|
End:
|
|
|
|
-->
|