Commit 3d5ddc0b authored by Tom Lane's avatar Tom Lane

Clean up wrong, misleading, or obsolete documentation about array types,

particularly in the CREATE TYPE reference page.  Fix some other errors
in the CREATE TYPE page, too.
parent f008976b
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/array.sgml,v 1.12 2001/09/09 17:21:44 petere Exp $ --> <!-- $Header: /cvsroot/pgsql/doc/src/sgml/array.sgml,v 1.13 2001/11/03 21:42:47 tgl Exp $ -->
<chapter id="arrays"> <chapter id="arrays">
<title>Arrays</title> <title>Arrays</title>
...@@ -23,15 +23,15 @@ CREATE TABLE sal_emp ( ...@@ -23,15 +23,15 @@ CREATE TABLE sal_emp (
<structname>sal_emp</structname> with a <type>text</type> string <structname>sal_emp</structname> with a <type>text</type> string
(<structfield>name</structfield>), a one-dimensional array of type (<structfield>name</structfield>), a one-dimensional array of type
<type>integer</type> (<structfield>pay_by_quarter</structfield>), <type>integer</type> (<structfield>pay_by_quarter</structfield>),
which shall represent the employee's salary by quarter, and a which represents the employee's salary by quarter, and a
two-dimensional array of <type>text</type> two-dimensional array of <type>text</type>
(<structfield>schedule</structfield>), which represents the (<structfield>schedule</structfield>), which represents the
employee's weekly schedule. employee's weekly schedule.
</para> </para>
<para> <para>
Now we do some <command>INSERT</command>s; note that when appending Now we do some <command>INSERT</command>s. Observe that to write an array
to an array, we enclose the values within braces and separate them value, we enclose the element values within braces and separate them
by commas. If you know C, this is not unlike the syntax for by commas. If you know C, this is not unlike the syntax for
initializing structures. initializing structures.
...@@ -200,8 +200,7 @@ SELECT * FROM sal_emp WHERE pay_by_quarter[1] = 10000 OR ...@@ -200,8 +200,7 @@ SELECT * FROM sal_emp WHERE pay_by_quarter[1] = 10000 OR
However, this quickly becomes tedious for large arrays, and is not However, this quickly becomes tedious for large arrays, and is not
helpful if the size of the array is unknown. Although it is not part helpful if the size of the array is unknown. Although it is not part
of the primary <productname>PostgreSQL</productname> distribution, of the primary <productname>PostgreSQL</productname> distribution,
in the contributions directory, there is an extension to there is an extension available that defines new functions and
<productname>PostgreSQL</productname> that defines new functions and
operators for iterating over array values. Using this, the above operators for iterating over array values. Using this, the above
query could be: query could be:
......
<!-- <!--
Documentation of the system catalogs, directed toward PostgreSQL developers Documentation of the system catalogs, directed toward PostgreSQL developers
$Header: /cvsroot/pgsql/doc/src/sgml/catalogs.sgml,v 2.26 2001/10/15 22:47:47 tgl Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/catalogs.sgml,v 2.27 2001/11/03 21:42:47 tgl Exp $
--> -->
<chapter id="catalogs"> <chapter id="catalogs">
...@@ -420,7 +420,9 @@ ...@@ -420,7 +420,9 @@
<entry><type>int4</type></entry> <entry><type>int4</type></entry>
<entry></entry> <entry></entry>
<entry> <entry>
Number of dimensions, if the column is an array; otherwise 0. Number of dimensions, if the column is an array type; otherwise 0.
(Presently, the number of dimensions of an array is not enforced,
so any nonzero value effectively means <quote>it's an array</>.)
</entry> </entry>
</row> </row>
...@@ -1064,7 +1066,7 @@ ...@@ -1064,7 +1066,7 @@
<entry><type>int2vector</type></entry> <entry><type>int2vector</type></entry>
<entry>pg_attribute.attnum</entry> <entry>pg_attribute.attnum</entry>
<entry> <entry>
This is an vector (array) of up to This is a vector (array) of up to
<symbol>INDEX_MAX_KEYS</symbol> values that indicate which <symbol>INDEX_MAX_KEYS</symbol> values that indicate which
table columns this index pertains to. For example a value of table columns this index pertains to. For example a value of
<literal>1 3</literal> would mean that the first and the third <literal>1 3</literal> would mean that the first and the third
...@@ -2336,7 +2338,9 @@ ...@@ -2336,7 +2338,9 @@
<entry>typdelim</entry> <entry>typdelim</entry>
<entry><type>char</type></entry> <entry><type>char</type></entry>
<entry></entry> <entry></entry>
<entry>Character that separates two values of this type when parsing array input</entry> <entry>Character that separates two values of this type when parsing
array input. Note that the delimiter is associated with the array
element datatype, not the array datatype.</entry>
</row> </row>
<row> <row>
...@@ -2360,14 +2364,17 @@ ...@@ -2360,14 +2364,17 @@
If <structfield>typelem</structfield> is not 0 then it If <structfield>typelem</structfield> is not 0 then it
identifies another row in <structname>pg_type</structname>. identifies another row in <structname>pg_type</structname>.
The current type can then be subscripted like an array yielding The current type can then be subscripted like an array yielding
values of type <structfield>typelem</structfield>. A non-zero values of type <structfield>typelem</structfield>. A
<structfield>typelem</structfield> does not guarantee this type <quote>true</quote> array type is variable length
to be a <quote>real</quote> array type; some ordinary (<structfield>typlen</structfield> = -1),
fixed-length types can also be subscripted (e.g., but some fixed-length (<structfield>typlen</structfield> &gt; 0) types
<type>oidvector</type>). Variable-length types can also have nonzero <structfield>typelem</structfield>, for example
<emphasis>not</emphasis> be turned into pseudo-arrays like <type>name</type> and <type>oidvector</type>.
that. Hence, the way to determine whether a type is a If a fixed-length type has a <structfield>typelem</structfield> then
<quote>true</quote> array type is typelem != 0 and typlen < 0. its internal representation must be N values of the
<structfield>typelem</structfield> datatype with no other data.
Variable-length array types have a header defined by the array
subroutines.
</entry> </entry>
</row> </row>
......
This diff is collapsed.
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/drop_type.sgml,v 1.11 2001/09/13 19:05:29 petere Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/ref/drop_type.sgml,v 1.12 2001/11/03 21:42:47 tgl Exp $
Postgres documentation Postgres documentation
--> -->
...@@ -105,7 +105,9 @@ ERROR: RemoveType: type '<replaceable class="parameter">typename</replaceable>' ...@@ -105,7 +105,9 @@ ERROR: RemoveType: type '<replaceable class="parameter">typename</replaceable>'
<para> <para>
It is the user's responsibility to remove any operators, It is the user's responsibility to remove any operators,
functions, aggregates, access methods, subtypes, and tables that functions, aggregates, access methods, subtypes, and tables that
use a deleted type. use a deleted type. However, the associated array datatype
(which was automatically created by <command>CREATE TYPE</command>)
will be removed automatically.
</para> </para>
</listitem> </listitem>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment