Skip to content

Commit bc8036f

Browse files
committed
Support arrays of composite types, including the rowtypes of regular tables
and views (but not system catalogs, nor sequences or toast tables). Get rid of the hardwired convention that a type's array type is named exactly "_type", instead using a new column pg_type.typarray to provide the linkage. (It still will be named "_type", though, except in odd corner cases such as maximum-length type names.) Along the way, make tracking of owner and schema dependencies for types more uniform: a type directly created by the user has these dependencies, while a table rowtype or auto-generated array type does not have them, but depends on its parent object instead. David Fetter, Andrew Dunstan, Tom Lane
1 parent b1110aa commit bc8036f

File tree

25 files changed

+697
-406
lines changed

25 files changed

+697
-406
lines changed

doc/src/sgml/array.sgml

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/array.sgml,v 1.60 2007/04/06 19:22:38 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/array.sgml,v 1.61 2007/05/11 17:57:11 tgl Exp $ -->
22

33
<sect1 id="arrays">
44
<title>Arrays</title>
@@ -10,8 +10,9 @@
1010
<para>
1111
<productname>PostgreSQL</productname> allows columns of a table to be
1212
defined as variable-length multidimensional arrays. Arrays of any
13-
built-in or user-defined base type or enum type can be created.
14-
(Arrays of composite types or domains are not yet supported, however.)
13+
built-in or user-defined base type, enum type, or composite type
14+
can be created.
15+
Arrays of domains are not yet supported.
1516
</para>
1617

1718
<sect2>

doc/src/sgml/catalogs.sgml

+16-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/catalogs.sgml,v 2.150 2007/04/06 22:33:41 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/catalogs.sgml,v 2.151 2007/05/11 17:57:11 tgl Exp $ -->
22
<!--
33
Documentation of the system catalogs, directed toward PostgreSQL developers
44
-->
@@ -4524,6 +4524,17 @@
45244524
</entry>
45254525
</row>
45264526

4527+
<row>
4528+
<entry><structfield>typarray</structfield></entry>
4529+
<entry><type>oid</type></entry>
4530+
<entry><literal><link linkend="catalog-pg-type"><structname>pg_type</structname></link>.oid</literal></entry>
4531+
<entry>
4532+
If <structfield>typarray</structfield> is not 0 then it
4533+
identifies another row in <structname>pg_type</structname>, which
4534+
is the <quote>true</quote> array type having this type as element
4535+
</entry>
4536+
</row>
4537+
45274538
<row>
45284539
<entry><structfield>typinput</structfield></entry>
45294540
<entry><type>regproc</type></entry>
@@ -4686,9 +4697,10 @@
46864697
<entry></entry>
46874698
<entry><para>
46884699
<structfield>typndims</structfield> is the number of array dimensions
4689-
for a domain that is an array (that is, <structfield>typbasetype</> is an array type;
4690-
the domain's <structfield>typelem</> will match the base type's <structfield>typelem</structfield>).
4691-
Zero for types other than array domains
4700+
for a domain that is an array (that is, <structfield>typbasetype</> is
4701+
an array type; the domain's <structfield>typelem</> will match the base
4702+
type's <structfield>typelem</structfield>).
4703+
Zero for types other than domains over array types
46924704
</para></entry>
46934705
</row>
46944706

doc/src/sgml/ref/create_type.sgml

+21-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/create_type.sgml,v 1.69 2007/04/02 03:49:37 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/create_type.sgml,v 1.70 2007/05/11 17:57:11 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -312,15 +312,17 @@ CREATE TYPE <replaceable class="parameter">name</replaceable>
312312
<title>Array Types</title>
313313

314314
<para>
315-
Whenever a user-defined base or enum data type is created,
315+
Whenever a user-defined type is created,
316316
<productname>PostgreSQL</productname> automatically creates an
317317
associated array type, whose name consists of the base type's
318-
name prepended with an underscore. The parser understands this
319-
naming convention, and translates requests for columns of type
320-
<literal>foo[]</> into requests for type <literal>_foo</>.
321-
The implicitly-created array type is variable length and uses the
318+
name prepended with an underscore, and truncated if necessary to keep
319+
it less than <symbol>NAMEDATALEN</symbol> bytes long. (If the name
320+
so generated collides with an existing type name, the process is
321+
repeated until a non-colliding name is found.)
322+
This implicitly-created array type is variable length and uses the
322323
built-in input and output functions <literal>array_in</> and
323-
<literal>array_out</>.
324+
<literal>array_out</>. The array type tracks any changes in its
325+
element type's owner or schema, and is dropped if the element type is.
324326
</para>
325327

326328
<para>
@@ -330,10 +332,9 @@ CREATE TYPE <replaceable class="parameter">name</replaceable>
330332
making a fixed-length type that happens to be internally an array of a number of
331333
identical things, and you want to allow these things to be accessed
332334
directly by subscripting, in addition to whatever operations you plan
333-
to provide for the type as a whole. For example, type <type>name</>
334-
allows its constituent <type>char</> elements to be accessed this way.
335-
A 2-D <type>point</> type could allow its two component numbers to be
336-
accessed like <literal>point[0]</> and <literal>point[1]</>.
335+
to provide for the type as a whole. For example, type <type>point</>
336+
is represented as just two floating-point numbers, which it allows to be
337+
accessed as <literal>point[0]</> and <literal>point[1]</>.
337338
Note that
338339
this facility only works for fixed-length types whose internal form
339340
is exactly a sequence of identical fixed-length fields. A subscriptable
@@ -529,12 +530,15 @@ CREATE TYPE <replaceable class="parameter">name</replaceable>
529530
<title>Notes</title>
530531

531532
<para>
532-
User-defined type names should not begin with the underscore character
533-
(<literal>_</literal>) and should only be 62 characters
534-
long (or in general <symbol>NAMEDATALEN</symbol> - 2, rather than
535-
the <symbol>NAMEDATALEN</symbol> - 1 characters allowed for other
536-
names). Type names beginning with underscore are reserved for
537-
internally-created array type names.
533+
It is best to avoid using type names that begin with the underscore
534+
character (<literal>_</literal>). <productname>PostgreSQL</productname>
535+
forms the name of an array type by prepending one or more underscores
536+
to the element type's name, and these names may collide with user-defined
537+
type names that begin with underscore. While the system will modify
538+
generated array type names to avoid collisions, this does not help if the
539+
conflicting array type already exists when you try to create your type.
540+
Also, various old client software may assume that names beginning with
541+
underscores always represent arrays.
538542
</para>
539543

540544
<para>

doc/src/sgml/syntax.sgml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/syntax.sgml,v 1.117 2007/02/20 14:04:50 momjian Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/syntax.sgml,v 1.118 2007/05/11 17:57:11 tgl Exp $ -->
22

33
<chapter id="sql-syntax">
44
<title>SQL Syntax</title>
@@ -131,10 +131,10 @@ INSERT INTO MY_TABLE VALUES (3, 'hi there');
131131
<para>
132132
<indexterm><primary>identifier</primary><secondary>length</secondary></indexterm>
133133
The system uses no more than <symbol>NAMEDATALEN</symbol>-1
134-
characters of an identifier; longer names can be written in
134+
bytes of an identifier; longer names can be written in
135135
commands, but they will be truncated. By default,
136136
<symbol>NAMEDATALEN</symbol> is 64 so the maximum identifier
137-
length is 63. If this limit is problematic, it can be raised by
137+
length is 63 bytes. If this limit is problematic, it can be raised by
138138
changing the <symbol>NAMEDATALEN</symbol> constant in
139139
<filename>src/include/pg_config_manual.h</filename>.
140140
</para>

src/backend/catalog/README

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
$PostgreSQL: pgsql/src/backend/catalog/README,v 1.10 2006/07/31 01:16:36 tgl Exp $
1+
$PostgreSQL: pgsql/src/backend/catalog/README,v 1.11 2007/05/11 17:57:11 tgl Exp $
22

33
This directory contains .c files that manipulate the system catalogs;
44
src/include/catalog contains the .h files that define the structure
@@ -86,9 +86,9 @@ general) assumes that the fixed-length portions of all system catalog
8686
tuples are in fact present, because it maps C struct declarations onto
8787
them. Thus, the variable-length fields must all be at the end, and
8888
only the variable-length fields of a catalog tuple are permitted to be
89-
NULL. For example, if you set pg_type.typdelim to be NULL, a
90-
piece of code will likely perform "typetup->typdelim" (or, worse,
91-
"typetyp->typelem", which follows typdelim). This will result in
89+
NULL. For example, if you set pg_type.typrelid to be NULL, a
90+
piece of code will likely perform "typetup->typrelid" (or, worse,
91+
"typetyp->typelem", which follows typrelid). This will result in
9292
random errors or even segmentation violations. Hence, do NOT insert
9393
catalog tuples that contain NULL attributes except in their
9494
variable-length portions! (The bootstrapping code is fairly good about

0 commit comments

Comments
 (0)