|
|
|
@ -1,5 +1,5 @@ |
|
|
|
|
<!-- |
|
|
|
|
$Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.110 2002/12/06 05:17:42 momjian Exp $ |
|
|
|
|
$Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.111 2003/01/15 18:01:04 momjian Exp $ |
|
|
|
|
--> |
|
|
|
|
|
|
|
|
|
<chapter id="datatype"> |
|
|
|
@ -86,18 +86,18 @@ $Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.110 2002/12/06 05:17:42 m |
|
|
|
|
<entry>binary data</entry> |
|
|
|
|
</row> |
|
|
|
|
|
|
|
|
|
<row> |
|
|
|
|
<entry><type>character(<replaceable>n</replaceable>)</type></entry> |
|
|
|
|
<entry><type>char(<replaceable>n</replaceable>)</type></entry> |
|
|
|
|
<entry>fixed-length character string</entry> |
|
|
|
|
</row> |
|
|
|
|
|
|
|
|
|
<row> |
|
|
|
|
<entry><type>character varying(<replaceable>n</replaceable>)</type></entry> |
|
|
|
|
<entry><type>varchar(<replaceable>n</replaceable>)</type></entry> |
|
|
|
|
<entry>variable-length character string</entry> |
|
|
|
|
</row> |
|
|
|
|
|
|
|
|
|
<row> |
|
|
|
|
<entry><type>character(<replaceable>n</replaceable>)</type></entry> |
|
|
|
|
<entry><type>char(<replaceable>n</replaceable>)</type></entry> |
|
|
|
|
<entry>fixed-length character string</entry> |
|
|
|
|
</row> |
|
|
|
|
|
|
|
|
|
<row> |
|
|
|
|
<entry><type>cidr</type></entry> |
|
|
|
|
<entry></entry> |
|
|
|
@ -248,7 +248,7 @@ $Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.110 2002/12/06 05:17:42 m |
|
|
|
|
The following types (or spellings thereof) are specified by |
|
|
|
|
<acronym>SQL</acronym>: <type>bit</type>, <type>bit |
|
|
|
|
varying</type>, <type>boolean</type>, <type>char</type>, |
|
|
|
|
<type>character</type>, <type>character varying</type>, |
|
|
|
|
<type>character varying</type>, <type>character</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>, |
|
|
|
@ -811,14 +811,14 @@ CREATE TABLE <replaceable class="parameter">tablename</replaceable> ( |
|
|
|
|
</row> |
|
|
|
|
</thead> |
|
|
|
|
<tbody> |
|
|
|
|
<row> |
|
|
|
|
<entry><type>character(<replaceable>n</>)</type>, <type>char(<replaceable>n</>)</type></entry> |
|
|
|
|
<entry>fixed-length, blank padded</entry> |
|
|
|
|
</row> |
|
|
|
|
<row> |
|
|
|
|
<entry><type>character varying(<replaceable>n</>)</type>, <type>varchar(<replaceable>n</>)</type></entry> |
|
|
|
|
<entry>variable-length with limit</entry> |
|
|
|
|
</row> |
|
|
|
|
<row> |
|
|
|
|
<entry><type>character(<replaceable>n</>)</type>, <type>char(<replaceable>n</>)</type></entry> |
|
|
|
|
<entry>fixed-length, blank padded</entry> |
|
|
|
|
</row> |
|
|
|
|
<row> |
|
|
|
|
<entry><type>text</type></entry> |
|
|
|
|
<entry>variable unlimited length</entry> |
|
|
|
@ -835,29 +835,29 @@ CREATE TABLE <replaceable class="parameter">tablename</replaceable> ( |
|
|
|
|
|
|
|
|
|
<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 |
|
|
|
|
<type>character varying(<replaceable>n</>)</type> and |
|
|
|
|
<type>character(<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 |
|
|
|
|
<acronym>SQL</acronym> 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 |
|
|
|
|
the string will be truncated to the maximum length. (This somewhat |
|
|
|
|
bizarre exception is required by the <acronym>SQL</acronym> |
|
|
|
|
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. |
|
|
|
|
</para> |
|
|
|
|
|
|
|
|
|
<note> |
|
|
|
|
<para> |
|
|
|
|
If one explicitly casts a value to |
|
|
|
|
<type>character(<replaceable>n</>)</type> or <type>character |
|
|
|
|
varying(<replaceable>n</>)</type>, then an overlength value will |
|
|
|
|
be truncated to <replaceable>n</> characters without raising an |
|
|
|
|
error. (This too is required by the <acronym>SQL</acronym> |
|
|
|
|
standard.) |
|
|
|
|
If one explicitly casts a value to <type>character |
|
|
|
|
varying(<replaceable>n</>)</type> or |
|
|
|
|
<type>character(<replaceable>n</>)</type>, then an over-length |
|
|
|
|
value will be truncated to <replaceable>n</> characters without |
|
|
|
|
raising an error. (This too is required by the |
|
|
|
|
<acronym>SQL</acronym> standard.) |
|
|
|
|
</para> |
|
|
|
|
</note> |
|
|
|
|
|
|
|
|
@ -870,14 +870,14 @@ CREATE TABLE <replaceable class="parameter">tablename</replaceable> ( |
|
|
|
|
</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 <productname>PostgreSQL</> extension. |
|
|
|
|
The notations <type>varchar(<replaceable>n</>)</type> and |
|
|
|
|
<type>char(<replaceable>n</>)</type> are aliases for <type>character |
|
|
|
|
varying(<replaceable>n</>)</type> and |
|
|
|
|
<type>character(<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 <productname>PostgreSQL</> extension. |
|
|
|
|
</para> |
|
|
|
|
|
|
|
|
|
<para> |
|
|
|
@ -961,19 +961,18 @@ SELECT b, char_length(b) FROM test2; |
|
|
|
|
|
|
|
|
|
<para> |
|
|
|
|
There are two other fixed-length character types in |
|
|
|
|
<productname>PostgreSQL</productname>, shown in <xref linkend="datatype-character-special-table">. |
|
|
|
|
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 64 bytes (63 usable characters plus terminator) |
|
|
|
|
but should be referenced using the constant |
|
|
|
|
<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. |
|
|
|
|
<productname>PostgreSQL</productname>, shown in <xref |
|
|
|
|
linkend="datatype-character-special-table">. 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 64 bytes (63 usable characters plus |
|
|
|
|
terminator) but should be referenced using the constant |
|
|
|
|
<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. |
|
|
|
|
</para> |
|
|
|
|
|
|
|
|
|
<table id="datatype-character-special-table"> |
|
|
|
|