~ubuntu-branches/ubuntu/oneiric/postgresql-9.1/oneiric-security

« back to all changes in this revision

Viewing changes to doc/src/sgml/man7/CREATE_TABLE.7

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2011-05-11 10:41:53 UTC
  • Revision ID: james.westby@ubuntu.com-20110511104153-psbh2o58553fv1m0
Tags: upstream-9.1~beta1
ImportĀ upstreamĀ versionĀ 9.1~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
'\" t
 
2
.\"     Title: CREATE TABLE
 
3
.\"    Author: The PostgreSQL Global Development Group
 
4
.\" Generator: DocBook XSL Stylesheets v1.75.1 <http://docbook.sf.net/>
 
5
.\"      Date: 2011-04-27
 
6
.\"    Manual: PostgreSQL 9.1beta1 Documentation
 
7
.\"    Source: PostgreSQL 9.1beta1
 
8
.\"  Language: English
 
9
.\"
 
10
.TH "CREATE TABLE" "7" "2011-04-27" "PostgreSQL 9.1beta1" "PostgreSQL 9.1beta1 Documentation"
 
11
.\" -----------------------------------------------------------------
 
12
.\" * set default formatting
 
13
.\" -----------------------------------------------------------------
 
14
.\" disable hyphenation
 
15
.nh
 
16
.\" disable justification (adjust text to left margin only)
 
17
.ad l
 
18
.\" -----------------------------------------------------------------
 
19
.\" * MAIN CONTENT STARTS HERE *
 
20
.\" -----------------------------------------------------------------
 
21
.SH "NAME"
 
22
CREATE_TABLE \- define a new table
 
23
.\" CREATE TABLE
 
24
.SH "SYNOPSIS"
 
25
.sp
 
26
.nf
 
27
CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXISTS ] \fItable_name\fR ( [
 
28
  { \fIcolumn_name\fR \fIdata_type\fR [ COLLATE \fIcollation\fR ] [ \fIcolumn_constraint\fR [ \&.\&.\&. ] ]
 
29
    | \fItable_constraint\fR
 
30
    | LIKE \fIparent_table\fR [ \fIlike_option\fR \&.\&.\&. ] }
 
31
    [, \&.\&.\&. ]
 
32
] )
 
33
[ INHERITS ( \fIparent_table\fR [, \&.\&.\&. ] ) ]
 
34
[ WITH ( \fIstorage_parameter\fR [= \fIvalue\fR] [, \&.\&.\&. ] ) | WITH OIDS | WITHOUT OIDS ]
 
35
[ ON COMMIT { PRESERVE ROWS | DELETE ROWS | DROP } ]
 
36
[ TABLESPACE \fItablespace\fR ]
 
37
 
 
38
CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXISTS ] \fItable_name\fR
 
39
    OF \fItype_name\fR [ (
 
40
  { \fIcolumn_name\fR WITH OPTIONS [ \fIcolumn_constraint\fR [ \&.\&.\&. ] ]
 
41
    | \fItable_constraint\fR }
 
42
    [, \&.\&.\&. ]
 
43
) ]
 
44
[ WITH ( \fIstorage_parameter\fR [= \fIvalue\fR] [, \&.\&.\&. ] ) | WITH OIDS | WITHOUT OIDS ]
 
45
[ ON COMMIT { PRESERVE ROWS | DELETE ROWS | DROP } ]
 
46
[ TABLESPACE \fItablespace\fR ]
 
47
 
 
48
where \fIcolumn_constraint\fR is:
 
49
 
 
50
[ CONSTRAINT \fIconstraint_name\fR ]
 
51
{ NOT NULL |
 
52
  NULL |
 
53
  CHECK ( \fIexpression\fR ) |
 
54
  DEFAULT \fIdefault_expr\fR |
 
55
  UNIQUE \fIindex_parameters\fR |
 
56
  PRIMARY KEY \fIindex_parameters\fR |
 
57
  REFERENCES \fIreftable\fR [ ( \fIrefcolumn\fR ) ] [ MATCH FULL | MATCH PARTIAL | MATCH SIMPLE ]
 
58
    [ ON DELETE \fIaction\fR ] [ ON UPDATE \fIaction\fR ] }
 
59
[ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ]
 
60
 
 
61
and \fItable_constraint\fR is:
 
62
 
 
63
[ CONSTRAINT \fIconstraint_name\fR ]
 
64
{ CHECK ( \fIexpression\fR ) |
 
65
  UNIQUE ( \fIcolumn_name\fR [, \&.\&.\&. ] ) \fIindex_parameters\fR |
 
66
  PRIMARY KEY ( \fIcolumn_name\fR [, \&.\&.\&. ] ) \fIindex_parameters\fR |
 
67
  EXCLUDE [ USING \fIindex_method\fR ] ( \fIexclude_element\fR WITH \fIoperator\fR [, \&.\&.\&. ] ) \fIindex_parameters\fR [ WHERE ( \fIpredicate\fR ) ] |
 
68
  FOREIGN KEY ( \fIcolumn_name\fR [, \&.\&.\&. ] ) REFERENCES \fIreftable\fR [ ( \fIrefcolumn\fR [, \&.\&.\&. ] ) ]
 
69
    [ MATCH FULL | MATCH PARTIAL | MATCH SIMPLE ] [ ON DELETE \fIaction\fR ] [ ON UPDATE \fIaction\fR ] }
 
70
[ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ]
 
71
 
 
72
and \fIlike_option\fR is:
 
73
 
 
74
{ INCLUDING | EXCLUDING } { DEFAULTS | CONSTRAINTS | INDEXES | STORAGE | COMMENTS | ALL }
 
75
 
 
76
\fIindex_parameters\fR in UNIQUE, PRIMARY KEY, and EXCLUDE constraints are:
 
77
 
 
78
[ WITH ( \fIstorage_parameter\fR [= \fIvalue\fR] [, \&.\&.\&. ] ) ]
 
79
[ USING INDEX TABLESPACE \fItablespace\fR ]
 
80
 
 
81
\fIexclude_element\fR in an EXCLUDE constraint is:
 
82
 
 
83
{ \fIcolumn\fR | ( \fIexpression\fR ) } [ \fIopclass\fR ] [ ASC | DESC ] [ NULLS { FIRST | LAST } ]
 
84
.fi
 
85
.SH "DESCRIPTION"
 
86
.PP
 
87
CREATE TABLE
 
88
will create a new, initially empty table in the current database\&. The table will be owned by the user issuing the command\&.
 
89
.PP
 
90
If a schema name is given (for example,
 
91
CREATE TABLE myschema\&.mytable \&.\&.\&.) then the table is created in the specified schema\&. Otherwise it is created in the current schema\&. Temporary tables exist in a special schema, so a schema name cannot be given when creating a temporary table\&. The name of the table must be distinct from the name of any other table, sequence, index, view, or foreign table in the same schema\&.
 
92
.PP
 
93
CREATE TABLE
 
94
also automatically creates a data type that represents the composite type corresponding to one row of the table\&. Therefore, tables cannot have the same name as any existing data type in the same schema\&.
 
95
.PP
 
96
The optional constraint clauses specify constraints (tests) that new or updated rows must satisfy for an insert or update operation to succeed\&. A constraint is an SQL object that helps define the set of valid values in the table in various ways\&.
 
97
.PP
 
98
There are two ways to define constraints: table constraints and column constraints\&. A column constraint is defined as part of a column definition\&. A table constraint definition is not tied to a particular column, and it can encompass more than one column\&. Every column constraint can also be written as a table constraint; a column constraint is only a notational convenience for use when the constraint only affects one column\&.
 
99
.SH "PARAMETERS"
 
100
.PP
 
101
TEMPORARY or TEMP
 
102
.RS 4
 
103
If specified, the table is created as a temporary table\&. Temporary tables are automatically dropped at the end of a session, or optionally at the end of the current transaction (see
 
104
ON COMMIT
 
105
below)\&. Existing permanent tables with the same name are not visible to the current session while the temporary table exists, unless they are referenced with schema\-qualified names\&. Any indexes created on a temporary table are automatically temporary as well\&.
 
106
.sp
 
107
The
 
108
autovacuum daemon
 
109
cannot access and therefore cannot vacuum or analyze temporary tables\&. For this reason, appropriate vacuum and analyze operations should be performed via session SQL commands\&. For example, if a temporary table is going to be used in complex queries, it is wise to run
 
110
ANALYZE
 
111
on the temporary table after it is populated\&.
 
112
.sp
 
113
Optionally,
 
114
GLOBAL
 
115
or
 
116
LOCAL
 
117
can be written before
 
118
TEMPORARY
 
119
or
 
120
TEMP\&. This makes no difference in
 
121
PostgreSQL, but see
 
122
COMPATIBILITY\&.
 
123
.RE
 
124
.PP
 
125
UNLOGGED
 
126
.RS 4
 
127
If specified, the table is created as an unlogged table\&. Data written to unlogged tables is not written to the write\-ahead log (see
 
128
Chapter 29, Reliability and the Write-Ahead Log, in the documentation), which makes them considerably faster than ordinary tables\&. However, they are not crash\-safe: an unlogged table is automatically truncated after a crash or unclean shutdown\&. The contents of an unlogged table are also not replicated to standby servers\&. Any indexes created on an unlogged table are automatically unlogged as well; however, unlogged
 
129
GiST indexes
 
130
are currently not supported and cannot be created on an unlogged table\&.
 
131
.RE
 
132
.PP
 
133
IF NOT EXISTS
 
134
.RS 4
 
135
Do not throw an error if a relation with the same name already exists\&. A notice is issued in this case\&. Note that there is no guarantee that the existing relation is anything like the one that would have been created\&.
 
136
.RE
 
137
.PP
 
138
\fItable_name\fR
 
139
.RS 4
 
140
The name (optionally schema\-qualified) of the table to be created\&.
 
141
.RE
 
142
.PP
 
143
OF \fItype_name\fR
 
144
.RS 4
 
145
Creates a
 
146
typed table, which takes its structure from the specified composite type (name optionally schema\-qualified)\&. A typed table is tied to its type; for example the table will be dropped if the type is dropped (with
 
147
DROP TYPE \&.\&.\&. CASCADE)\&.
 
148
.sp
 
149
When a typed table is created, then the data types of the columns are determined by the underlying composite type and are not specified by the
 
150
CREATE TABLE
 
151
command\&. But the
 
152
CREATE TABLE
 
153
command can add defaults and constraints to the table and can specify storage parameters\&.
 
154
.RE
 
155
.PP
 
156
\fIcolumn_name\fR
 
157
.RS 4
 
158
The name of a column to be created in the new table\&.
 
159
.RE
 
160
.PP
 
161
\fIdata_type\fR
 
162
.RS 4
 
163
The data type of the column\&. This can include array specifiers\&. For more information on the data types supported by
 
164
PostgreSQL, refer to
 
165
Chapter 8, Data Types, in the documentation\&.
 
166
.RE
 
167
.PP
 
168
COLLATE \fIcollation\fR
 
169
.RS 4
 
170
The
 
171
COLLATE
 
172
clause assigns a collation to the column (which must be of a collatable data type)\&. If not specified, the column data type\(aqs default collation is used\&.
 
173
.RE
 
174
.PP
 
175
INHERITS ( \fIparent_table\fR [, \&.\&.\&. ] )
 
176
.RS 4
 
177
The optional
 
178
INHERITS
 
179
clause specifies a list of tables from which the new table automatically inherits all columns\&.
 
180
.sp
 
181
Use of
 
182
INHERITS
 
183
creates a persistent relationship between the new child table and its parent table(s)\&. Schema modifications to the parent(s) normally propagate to children as well, and by default the data of the child table is included in scans of the parent(s)\&.
 
184
.sp
 
185
If the same column name exists in more than one parent table, an error is reported unless the data types of the columns match in each of the parent tables\&. If there is no conflict, then the duplicate columns are merged to form a single column in the new table\&. If the column name list of the new table contains a column name that is also inherited, the data type must likewise match the inherited column(s), and the column definitions are merged into one\&. If the new table explicitly specifies a default value for the column, this default overrides any defaults from inherited declarations of the column\&. Otherwise, any parents that specify default values for the column must all specify the same default, or an error will be reported\&.
 
186
.sp
 
187
CHECK
 
188
constraints are merged in essentially the same way as columns: if multiple parent tables and/or the new table definition contain identically\-named
 
189
CHECK
 
190
constraints, these constraints must all have the same check expression, or an error will be reported\&. Constraints having the same name and expression will be merged into one copy\&. Notice that an unnamed
 
191
CHECK
 
192
constraint in the new table will never be merged, since a unique name will always be chosen for it\&.
 
193
.sp
 
194
Column
 
195
STORAGE
 
196
settings are also copied from parent tables\&.
 
197
.RE
 
198
.PP
 
199
LIKE \fIparent_table\fR [ \fIlike_option\fR \&.\&.\&. ]
 
200
.RS 4
 
201
The
 
202
LIKE
 
203
clause specifies a table from which the new table automatically copies all column names, their data types, and their not\-null constraints\&.
 
204
.sp
 
205
Unlike
 
206
INHERITS, the new table and original table are completely decoupled after creation is complete\&. Changes to the original table will not be applied to the new table, and it is not possible to include data of the new table in scans of the original table\&.
 
207
.sp
 
208
Default expressions for the copied column definitions will only be copied if
 
209
INCLUDING DEFAULTS
 
210
is specified\&. The default behavior is to exclude default expressions, resulting in the copied columns in the new table having null defaults\&.
 
211
.sp
 
212
Not\-null constraints are always copied to the new table\&.
 
213
CHECK
 
214
constraints will only be copied if
 
215
INCLUDING CONSTRAINTS
 
216
is specified; other types of constraints will never be copied\&. Also, no distinction is made between column constraints and table constraints \(em when constraints are requested, all check constraints are copied\&.
 
217
.sp
 
218
Any indexes on the original table will not be created on the new table, unless the
 
219
INCLUDING INDEXES
 
220
clause is specified\&.
 
221
.sp
 
222
STORAGE
 
223
settings for the copied column definitions will only be copied if
 
224
INCLUDING STORAGE
 
225
is specified\&. The default behavior is to exclude
 
226
STORAGE
 
227
settings, resulting in the copied columns in the new table having type\-specific default settings\&. For more on
 
228
STORAGE
 
229
settings, see
 
230
Section 55.2, \(lqTOAST\(rq, in the documentation\&.
 
231
.sp
 
232
Comments for the copied columns, constraints, and indexes will only be copied if
 
233
INCLUDING COMMENTS
 
234
is specified\&. The default behavior is to exclude comments, resulting in the copied columns and constraints in the new table having no comments\&.
 
235
.sp
 
236
INCLUDING ALL
 
237
is an abbreviated form of
 
238
INCLUDING DEFAULTS INCLUDING CONSTRAINTS INCLUDING INDEXES INCLUDING STORAGE INCLUDING COMMENTS\&.
 
239
.sp
 
240
Note also that unlike
 
241
INHERITS, columns and constraints copied by
 
242
LIKE
 
243
are not merged with similarly named columns and constraints\&. If the same name is specified explicitly or in another
 
244
LIKE
 
245
clause, an error is signalled\&.
 
246
.RE
 
247
.PP
 
248
CONSTRAINT \fIconstraint_name\fR
 
249
.RS 4
 
250
An optional name for a column or table constraint\&. If the constraint is violated, the constraint name is present in error messages, so constraint names like
 
251
col must be positive
 
252
can be used to communicate helpful constraint information to client applications\&. (Double\-quotes are needed to specify constraint names that contain spaces\&.) If a constraint name is not specified, the system generates a name\&.
 
253
.RE
 
254
.PP
 
255
NOT NULL
 
256
.RS 4
 
257
The column is not allowed to contain null values\&.
 
258
.RE
 
259
.PP
 
260
NULL
 
261
.RS 4
 
262
The column is allowed to contain null values\&. This is the default\&.
 
263
.sp
 
264
This clause is only provided for compatibility with non\-standard SQL databases\&. Its use is discouraged in new applications\&.
 
265
.RE
 
266
.PP
 
267
CHECK ( \fIexpression\fR )
 
268
.RS 4
 
269
The
 
270
CHECK
 
271
clause specifies an expression producing a Boolean result which new or updated rows must satisfy for an insert or update operation to succeed\&. Expressions evaluating to TRUE or UNKNOWN succeed\&. Should any row of an insert or update operation produce a FALSE result an error exception is raised and the insert or update does not alter the database\&. A check constraint specified as a column constraint should reference that column\(aqs value only, while an expression appearing in a table constraint can reference multiple columns\&.
 
272
.sp
 
273
Currently,
 
274
CHECK
 
275
expressions cannot contain subqueries nor refer to variables other than columns of the current row\&.
 
276
.RE
 
277
.PP
 
278
DEFAULT \fIdefault_expr\fR
 
279
.RS 4
 
280
The
 
281
DEFAULT
 
282
clause assigns a default data value for the column whose column definition it appears within\&. The value is any variable\-free expression (subqueries and cross\-references to other columns in the current table are not allowed)\&. The data type of the default expression must match the data type of the column\&.
 
283
.sp
 
284
The default expression will be used in any insert operation that does not specify a value for the column\&. If there is no default for a column, then the default is null\&.
 
285
.RE
 
286
.PP
 
287
UNIQUE (column constraint), UNIQUE ( \fIcolumn_name\fR [, \&.\&.\&. ] ) (table constraint)
 
288
.RS 4
 
289
The
 
290
UNIQUE
 
291
constraint specifies that a group of one or more columns of a table can contain only unique values\&. The behavior of the unique table constraint is the same as that for column constraints, with the additional capability to span multiple columns\&.
 
292
.sp
 
293
For the purpose of a unique constraint, null values are not considered equal\&.
 
294
.sp
 
295
Each unique table constraint must name a set of columns that is different from the set of columns named by any other unique or primary key constraint defined for the table\&. (Otherwise it would just be the same constraint listed twice\&.)
 
296
.RE
 
297
.PP
 
298
PRIMARY KEY (column constraint), PRIMARY KEY ( \fIcolumn_name\fR [, \&.\&.\&. ] ) (table constraint)
 
299
.RS 4
 
300
The primary key constraint specifies that a column or columns of a table can contain only unique (non\-duplicate), nonnull values\&. Technically,
 
301
PRIMARY KEY
 
302
is merely a combination of
 
303
UNIQUE
 
304
and
 
305
NOT NULL, but identifying a set of columns as primary key also provides metadata about the design of the schema, as a primary key implies that other tables can rely on this set of columns as a unique identifier for rows\&.
 
306
.sp
 
307
Only one primary key can be specified for a table, whether as a column constraint or a table constraint\&.
 
308
.sp
 
309
The primary key constraint should name a set of columns that is different from other sets of columns named by any unique constraint defined for the same table\&.
 
310
.RE
 
311
.PP
 
312
EXCLUDE [ USING \fIindex_method\fR ] ( \fIexclude_element\fR WITH \fIoperator\fR [, \&.\&.\&. ] ) \fIindex_parameters\fR [ WHERE ( \fIpredicate\fR ) ]
 
313
.RS 4
 
314
The
 
315
EXCLUDE
 
316
clause defines an exclusion constraint, which guarantees that if any two rows are compared on the specified column(s) or expression(s) using the specified operator(s), not all of these comparisons will return
 
317
TRUE\&. If all of the specified operators test for equality, this is equivalent to a
 
318
UNIQUE
 
319
constraint, although an ordinary unique constraint will be faster\&. However, exclusion constraints can specify constraints that are more general than simple equality\&. For example, you can specify a constraint that no two rows in the table contain overlapping circles (see
 
320
Section 8.8, \(lqGeometric Types\(rq, in the documentation) by using the
 
321
&&
 
322
operator\&.
 
323
.sp
 
324
Exclusion constraints are implemented using an index, so each specified operator must be associated with an appropriate operator class (see
 
325
Section 11.9, \(lqOperator Classes and Operator Families\(rq, in the documentation) for the index access method
 
326
\fIindex_method\fR\&. The operators are required to be commutative\&. Each
 
327
\fIexclude_element\fR
 
328
can optionally specify an operator class and/or ordering options; these are described fully under
 
329
CREATE INDEX (\fBCREATE_INDEX\fR(7))\&.
 
330
.sp
 
331
The access method must support
 
332
amgettuple
 
333
(see
 
334
Chapter 52, Index Access Method Interface Definition, in the documentation); at present this means
 
335
GIN
 
336
cannot be used\&. Although it\(aqs allowed, there is little point in using B\-tree or hash indexes with an exclusion constraint, because this does nothing that an ordinary unique constraint doesn\(aqt do better\&. So in practice the access method will always be
 
337
GiST\&.
 
338
.sp
 
339
The
 
340
\fIpredicate\fR
 
341
allows you to specify an exclusion constraint on a subset of the table; internally this creates a partial index\&. Note that parentheses are required around the predicate\&.
 
342
.RE
 
343
.PP
 
344
REFERENCES \fIreftable\fR [ ( \fIrefcolumn\fR ) ] [ MATCH \fImatchtype\fR ] [ ON DELETE \fIaction\fR ] [ ON UPDATE \fIaction\fR ] (column constraint), FOREIGN KEY ( \fIcolumn\fR [, \&.\&.\&. ] ) REFERENCES \fIreftable\fR [ ( \fIrefcolumn\fR [, \&.\&.\&. ] ) ] [ MATCH \fImatchtype\fR ] [ ON DELETE \fIaction\fR ] [ ON UPDATE \fIaction\fR ] (table constraint)
 
345
.RS 4
 
346
These clauses specify a foreign key constraint, which requires that a group of one or more columns of the new table must only contain values that match values in the referenced column(s) of some row of the referenced table\&. If
 
347
\fIrefcolumn\fR
 
348
is omitted, the primary key of the
 
349
\fIreftable\fR
 
350
is used\&. The referenced columns must be the columns of a non\-deferrable unique or primary key constraint in the referenced table\&. Note that foreign key constraints cannot be defined between temporary tables and permanent tables\&.
 
351
.sp
 
352
A value inserted into the referencing column(s) is matched against the values of the referenced table and referenced columns using the given match type\&. There are three match types:
 
353
MATCH FULL,
 
354
MATCH PARTIAL, and
 
355
MATCH SIMPLE, which is also the default\&.
 
356
MATCH FULL
 
357
will not allow one column of a multicolumn foreign key to be null unless all foreign key columns are null\&.
 
358
MATCH SIMPLE
 
359
allows some foreign key columns to be null while other parts of the foreign key are not null\&.
 
360
MATCH PARTIAL
 
361
is not yet implemented\&.
 
362
.sp
 
363
In addition, when the data in the referenced columns is changed, certain actions are performed on the data in this table\(aqs columns\&. The
 
364
ON DELETE
 
365
clause specifies the action to perform when a referenced row in the referenced table is being deleted\&. Likewise, the
 
366
ON UPDATE
 
367
clause specifies the action to perform when a referenced column in the referenced table is being updated to a new value\&. If the row is updated, but the referenced column is not actually changed, no action is done\&. Referential actions other than the
 
368
NO ACTION
 
369
check cannot be deferred, even if the constraint is declared deferrable\&. There are the following possible actions for each clause:
 
370
.PP
 
371
NO ACTION
 
372
.RS 4
 
373
Produce an error indicating that the deletion or update would create a foreign key constraint violation\&. If the constraint is deferred, this error will be produced at constraint check time if there still exist any referencing rows\&. This is the default action\&.
 
374
.RE
 
375
.PP
 
376
RESTRICT
 
377
.RS 4
 
378
Produce an error indicating that the deletion or update would create a foreign key constraint violation\&. This is the same as
 
379
NO ACTION
 
380
except that the check is not deferrable\&.
 
381
.RE
 
382
.PP
 
383
CASCADE
 
384
.RS 4
 
385
Delete any rows referencing the deleted row, or update the value of the referencing column to the new value of the referenced column, respectively\&.
 
386
.RE
 
387
.PP
 
388
SET NULL
 
389
.RS 4
 
390
Set the referencing column(s) to null\&.
 
391
.RE
 
392
.PP
 
393
SET DEFAULT
 
394
.RS 4
 
395
Set the referencing column(s) to their default values\&.
 
396
.RE
 
397
.sp
 
398
If the referenced column(s) are changed frequently, it might be wise to add an index to the foreign key column so that referential actions associated with the foreign key column can be performed more efficiently\&.
 
399
.RE
 
400
.PP
 
401
DEFERRABLE, NOT DEFERRABLE
 
402
.RS 4
 
403
This controls whether the constraint can be deferred\&. A constraint that is not deferrable will be checked immediately after every command\&. Checking of constraints that are deferrable can be postponed until the end of the transaction (using the
 
404
SET CONSTRAINTS (\fBSET_CONSTRAINTS\fR(7))
 
405
command)\&.
 
406
NOT DEFERRABLE
 
407
is the default\&. Currently, only
 
408
UNIQUE,
 
409
PRIMARY KEY,
 
410
EXCLUDE, and
 
411
REFERENCES
 
412
(foreign key) constraints accept this clause\&.
 
413
NOT NULL
 
414
and
 
415
CHECK
 
416
constraints are not deferrable\&.
 
417
.RE
 
418
.PP
 
419
INITIALLY IMMEDIATE, INITIALLY DEFERRED
 
420
.RS 4
 
421
If a constraint is deferrable, this clause specifies the default time to check the constraint\&. If the constraint is
 
422
INITIALLY IMMEDIATE, it is checked after each statement\&. This is the default\&. If the constraint is
 
423
INITIALLY DEFERRED, it is checked only at the end of the transaction\&. The constraint check time can be altered with the
 
424
SET CONSTRAINTS (\fBSET_CONSTRAINTS\fR(7))
 
425
command\&.
 
426
.RE
 
427
.PP
 
428
WITH ( \fIstorage_parameter\fR [= \fIvalue\fR] [, \&.\&.\&. ] )
 
429
.RS 4
 
430
This clause specifies optional storage parameters for a table or index; see
 
431
Storage Parameters
 
432
for more information\&. The
 
433
WITH
 
434
clause for a table can also include
 
435
OIDS=TRUE
 
436
(or just
 
437
OIDS) to specify that rows of the new table should have OIDs (object identifiers) assigned to them, or
 
438
OIDS=FALSE
 
439
to specify that the rows should not have OIDs\&. If
 
440
OIDS
 
441
is not specified, the default setting depends upon the
 
442
default_with_oids
 
443
configuration parameter\&. (If the new table inherits from any tables that have OIDs, then
 
444
OIDS=TRUE
 
445
is forced even if the command says
 
446
OIDS=FALSE\&.)
 
447
.sp
 
448
If
 
449
OIDS=FALSE
 
450
is specified or implied, the new table does not store OIDs and no OID will be assigned for a row inserted into it\&. This is generally considered worthwhile, since it will reduce OID consumption and thereby postpone the wraparound of the 32\-bit OID counter\&. Once the counter wraps around, OIDs can no longer be assumed to be unique, which makes them considerably less useful\&. In addition, excluding OIDs from a table reduces the space required to store the table on disk by 4 bytes per row (on most machines), slightly improving performance\&.
 
451
.sp
 
452
To remove OIDs from a table after it has been created, use
 
453
ALTER TABLE (\fBALTER_TABLE\fR(7))\&.
 
454
.RE
 
455
.PP
 
456
WITH OIDS, WITHOUT OIDS
 
457
.RS 4
 
458
These are obsolescent syntaxes equivalent to
 
459
WITH (OIDS)
 
460
and
 
461
WITH (OIDS=FALSE), respectively\&. If you wish to give both an
 
462
OIDS
 
463
setting and storage parameters, you must use the
 
464
WITH ( \&.\&.\&. )
 
465
syntax; see above\&.
 
466
.RE
 
467
.PP
 
468
ON COMMIT
 
469
.RS 4
 
470
The behavior of temporary tables at the end of a transaction block can be controlled using
 
471
ON COMMIT\&. The three options are:
 
472
.PP
 
473
PRESERVE ROWS
 
474
.RS 4
 
475
No special action is taken at the ends of transactions\&. This is the default behavior\&.
 
476
.RE
 
477
.PP
 
478
DELETE ROWS
 
479
.RS 4
 
480
All rows in the temporary table will be deleted at the end of each transaction block\&. Essentially, an automatic
 
481
\fBTRUNCATE\fR(7)
 
482
is done at each commit\&.
 
483
.RE
 
484
.PP
 
485
DROP
 
486
.RS 4
 
487
The temporary table will be dropped at the end of the current transaction block\&.
 
488
.RE
 
489
.RE
 
490
.PP
 
491
TABLESPACE \fItablespace\fR
 
492
.RS 4
 
493
The
 
494
\fItablespace\fR
 
495
is the name of the tablespace in which the new table is to be created\&. If not specified,
 
496
default_tablespace
 
497
is consulted, or
 
498
temp_tablespaces
 
499
if the table is temporary\&.
 
500
.RE
 
501
.PP
 
502
USING INDEX TABLESPACE \fItablespace\fR
 
503
.RS 4
 
504
This clause allows selection of the tablespace in which the index associated with a
 
505
UNIQUE,
 
506
PRIMARY KEY, or
 
507
EXCLUDE
 
508
constraint will be created\&. If not specified,
 
509
default_tablespace
 
510
is consulted, or
 
511
temp_tablespaces
 
512
if the table is temporary\&.
 
513
.RE
 
514
.SS "Storage Parameters"
 
515
.\" storage parameters
 
516
.PP
 
517
The
 
518
WITH
 
519
clause can specify
 
520
storage parameters
 
521
for tables, and for indexes associated with a
 
522
UNIQUE,
 
523
PRIMARY KEY, or
 
524
EXCLUDE
 
525
constraint\&. Storage parameters for indexes are documented in
 
526
CREATE INDEX (\fBCREATE_INDEX\fR(7))\&. The storage parameters currently available for tables are listed below\&. For each parameter, unless noted, there is an additional parameter with the same name prefixed with
 
527
toast\&., which can be used to control the behavior of the table\(aqs secondary
 
528
TOAST
 
529
table, if any (see
 
530
Section 55.2, \(lqTOAST\(rq, in the documentation
 
531
for more information about TOAST)\&. Note that the TOAST table inherits the
 
532
autovacuum_*
 
533
values from its parent table, if there are no
 
534
toast\&.autovacuum_*
 
535
settings set\&.
 
536
.PP
 
537
fillfactor (integer)
 
538
.RS 4
 
539
The fillfactor for a table is a percentage between 10 and 100\&. 100 (complete packing) is the default\&. When a smaller fillfactor is specified,
 
540
INSERT
 
541
operations pack table pages only to the indicated percentage; the remaining space on each page is reserved for updating rows on that page\&. This gives
 
542
UPDATE
 
543
a chance to place the updated copy of a row on the same page as the original, which is more efficient than placing it on a different page\&. For a table whose entries are never updated, complete packing is the best choice, but in heavily updated tables smaller fillfactors are appropriate\&. This parameter cannot be set for TOAST tables\&.
 
544
.RE
 
545
.PP
 
546
autovacuum_enabled, toast\&.autovacuum_enabled (boolean)
 
547
.RS 4
 
548
Enables or disables the autovacuum daemon on a particular table\&. If true, the autovacuum daemon will initiate a
 
549
VACUUM
 
550
operation on a particular table when the number of updated or deleted tuples exceeds
 
551
autovacuum_vacuum_threshold
 
552
plus
 
553
autovacuum_vacuum_scale_factor
 
554
times the number of live tuples currently estimated to be in the relation\&. Similarly, it will initiate an
 
555
ANALYZE
 
556
operation when the number of inserted, updated or deleted tuples exceeds
 
557
autovacuum_analyze_threshold
 
558
plus
 
559
autovacuum_analyze_scale_factor
 
560
times the number of live tuples currently estimated to be in the relation\&. If false, this table will not be autovacuumed, except to prevent transaction Id wraparound\&. See
 
561
Section 23.1.4, \(lqPreventing Transaction ID Wraparound Failures\(rq, in the documentation
 
562
for more about wraparound prevention\&. Observe that this variable inherits its value from the
 
563
autovacuum
 
564
setting\&.
 
565
.RE
 
566
.PP
 
567
autovacuum_vacuum_threshold, toast\&.autovacuum_vacuum_threshold (integer)
 
568
.RS 4
 
569
Minimum number of updated or deleted tuples before initiate a
 
570
VACUUM
 
571
operation on a particular table\&.
 
572
.RE
 
573
.PP
 
574
autovacuum_vacuum_scale_factor, toast\&.autovacuum_vacuum_scale_factor (float4)
 
575
.RS 4
 
576
Multiplier for
 
577
reltuples
 
578
to add to
 
579
autovacuum_vacuum_threshold\&.
 
580
.RE
 
581
.PP
 
582
autovacuum_analyze_threshold (integer)
 
583
.RS 4
 
584
Minimum number of inserted, updated, or deleted tuples before initiate an
 
585
ANALYZE
 
586
operation on a particular table\&.
 
587
.RE
 
588
.PP
 
589
autovacuum_analyze_scale_factor (float4)
 
590
.RS 4
 
591
Multiplier for
 
592
reltuples
 
593
to add to
 
594
autovacuum_analyze_threshold\&.
 
595
.RE
 
596
.PP
 
597
autovacuum_vacuum_cost_delay, toast\&.autovacuum_vacuum_cost_delay (integer)
 
598
.RS 4
 
599
Custom
 
600
autovacuum_vacuum_cost_delay
 
601
parameter\&.
 
602
.RE
 
603
.PP
 
604
autovacuum_vacuum_cost_limit, toast\&.autovacuum_vacuum_cost_limit (integer)
 
605
.RS 4
 
606
Custom
 
607
autovacuum_vacuum_cost_limit
 
608
parameter\&.
 
609
.RE
 
610
.PP
 
611
autovacuum_freeze_min_age, toast\&.autovacuum_freeze_min_age (integer)
 
612
.RS 4
 
613
Custom
 
614
vacuum_freeze_min_age
 
615
parameter\&. Note that autovacuum will ignore attempts to set a per\-table
 
616
autovacuum_freeze_min_age
 
617
larger than the half system\-wide
 
618
autovacuum_freeze_max_age
 
619
setting\&.
 
620
.RE
 
621
.PP
 
622
autovacuum_freeze_max_age, toast\&.autovacuum_freeze_max_age (integer)
 
623
.RS 4
 
624
Custom
 
625
autovacuum_freeze_max_age
 
626
parameter\&. Note that autovacuum will ignore attempts to set a per\-table
 
627
autovacuum_freeze_max_age
 
628
larger than the system\-wide setting (it can only be set smaller)\&. Note that while you can set
 
629
autovacuum_freeze_max_age
 
630
very small, or even zero, this is usually unwise since it will force frequent vacuuming\&.
 
631
.RE
 
632
.PP
 
633
autovacuum_freeze_table_age, toast\&.autovacuum_freeze_table_age (integer)
 
634
.RS 4
 
635
Custom
 
636
vacuum_freeze_table_age
 
637
parameter\&.
 
638
.RE
 
639
.SH "NOTES"
 
640
.PP
 
641
Using OIDs in new applications is not recommended: where possible, using a
 
642
SERIAL
 
643
or other sequence generator as the table\(aqs primary key is preferred\&. However, if your application does make use of OIDs to identify specific rows of a table, it is recommended to create a unique constraint on the
 
644
oid
 
645
column of that table, to ensure that OIDs in the table will indeed uniquely identify rows even after counter wraparound\&. Avoid assuming that OIDs are unique across tables; if you need a database\-wide unique identifier, use the combination of
 
646
tableoid
 
647
and row OID for the purpose\&.
 
648
.if n \{\
 
649
.sp
 
650
.\}
 
651
.RS 4
 
652
.it 1 an-trap
 
653
.nr an-no-space-flag 1
 
654
.nr an-break-flag 1
 
655
.br
 
656
.ps +1
 
657
\fBTip\fR
 
658
.ps -1
 
659
.br
 
660
.PP
 
661
The use of
 
662
OIDS=FALSE
 
663
is not recommended for tables with no primary key, since without either an OID or a unique data key, it is difficult to identify specific rows\&.
 
664
.sp .5v
 
665
.RE
 
666
.PP
 
667
PostgreSQL
 
668
automatically creates an index for each unique constraint and primary key constraint to enforce uniqueness\&. Thus, it is not necessary to create an index explicitly for primary key columns\&. (See
 
669
CREATE INDEX (\fBCREATE_INDEX\fR(7))
 
670
for more information\&.)
 
671
.PP
 
672
Unique constraints and primary keys are not inherited in the current implementation\&. This makes the combination of inheritance and unique constraints rather dysfunctional\&.
 
673
.PP
 
674
A table cannot have more than 1600 columns\&. (In practice, the effective limit is usually lower because of tuple\-length constraints\&.)
 
675
.SH "EXAMPLES"
 
676
.PP
 
677
Create table
 
678
films
 
679
and table
 
680
distributors:
 
681
.sp
 
682
.if n \{\
 
683
.RS 4
 
684
.\}
 
685
.nf
 
686
CREATE TABLE films (
 
687
    code        char(5) CONSTRAINT firstkey PRIMARY KEY,
 
688
    title       varchar(40) NOT NULL,
 
689
    did         integer NOT NULL,
 
690
    date_prod   date,
 
691
    kind        varchar(10),
 
692
    len         interval hour to minute
 
693
);
 
694
.fi
 
695
.if n \{\
 
696
.RE
 
697
.\}
 
698
.sp
 
699
.if n \{\
 
700
.RS 4
 
701
.\}
 
702
.nf
 
703
CREATE TABLE distributors (
 
704
     did    integer PRIMARY KEY DEFAULT nextval(\(aqserial\(aq),
 
705
     name   varchar(40) NOT NULL CHECK (name <> \(aq\(aq)
 
706
);
 
707
.fi
 
708
.if n \{\
 
709
.RE
 
710
.\}
 
711
.PP
 
712
Create a table with a 2\-dimensional array:
 
713
.sp
 
714
.if n \{\
 
715
.RS 4
 
716
.\}
 
717
.nf
 
718
CREATE TABLE array_int (
 
719
    vector  int[][]
 
720
);
 
721
.fi
 
722
.if n \{\
 
723
.RE
 
724
.\}
 
725
.PP
 
726
Define a unique table constraint for the table
 
727
films\&. Unique table constraints can be defined on one or more columns of the table:
 
728
.sp
 
729
.if n \{\
 
730
.RS 4
 
731
.\}
 
732
.nf
 
733
CREATE TABLE films (
 
734
    code        char(5),
 
735
    title       varchar(40),
 
736
    did         integer,
 
737
    date_prod   date,
 
738
    kind        varchar(10),
 
739
    len         interval hour to minute,
 
740
    CONSTRAINT production UNIQUE(date_prod)
 
741
);
 
742
.fi
 
743
.if n \{\
 
744
.RE
 
745
.\}
 
746
.PP
 
747
Define a check column constraint:
 
748
.sp
 
749
.if n \{\
 
750
.RS 4
 
751
.\}
 
752
.nf
 
753
CREATE TABLE distributors (
 
754
    did     integer CHECK (did > 100),
 
755
    name    varchar(40)
 
756
);
 
757
.fi
 
758
.if n \{\
 
759
.RE
 
760
.\}
 
761
.PP
 
762
Define a check table constraint:
 
763
.sp
 
764
.if n \{\
 
765
.RS 4
 
766
.\}
 
767
.nf
 
768
CREATE TABLE distributors (
 
769
    did     integer,
 
770
    name    varchar(40)
 
771
    CONSTRAINT con1 CHECK (did > 100 AND name <> \(aq\(aq)
 
772
);
 
773
.fi
 
774
.if n \{\
 
775
.RE
 
776
.\}
 
777
.PP
 
778
Define a primary key table constraint for the table
 
779
films:
 
780
.sp
 
781
.if n \{\
 
782
.RS 4
 
783
.\}
 
784
.nf
 
785
CREATE TABLE films (
 
786
    code        char(5),
 
787
    title       varchar(40),
 
788
    did         integer,
 
789
    date_prod   date,
 
790
    kind        varchar(10),
 
791
    len         interval hour to minute,
 
792
    CONSTRAINT code_title PRIMARY KEY(code,title)
 
793
);
 
794
.fi
 
795
.if n \{\
 
796
.RE
 
797
.\}
 
798
.PP
 
799
Define a primary key constraint for table
 
800
distributors\&. The following two examples are equivalent, the first using the table constraint syntax, the second the column constraint syntax:
 
801
.sp
 
802
.if n \{\
 
803
.RS 4
 
804
.\}
 
805
.nf
 
806
CREATE TABLE distributors (
 
807
    did     integer,
 
808
    name    varchar(40),
 
809
    PRIMARY KEY(did)
 
810
);
 
811
.fi
 
812
.if n \{\
 
813
.RE
 
814
.\}
 
815
.sp
 
816
.if n \{\
 
817
.RS 4
 
818
.\}
 
819
.nf
 
820
CREATE TABLE distributors (
 
821
    did     integer PRIMARY KEY,
 
822
    name    varchar(40)
 
823
);
 
824
.fi
 
825
.if n \{\
 
826
.RE
 
827
.\}
 
828
.PP
 
829
Assign a literal constant default value for the column
 
830
name, arrange for the default value of column
 
831
did
 
832
to be generated by selecting the next value of a sequence object, and make the default value of
 
833
modtime
 
834
be the time at which the row is inserted:
 
835
.sp
 
836
.if n \{\
 
837
.RS 4
 
838
.\}
 
839
.nf
 
840
CREATE TABLE distributors (
 
841
    name      varchar(40) DEFAULT \(aqLuso Films\(aq,
 
842
    did       integer DEFAULT nextval(\(aqdistributors_serial\(aq),
 
843
    modtime   timestamp DEFAULT current_timestamp
 
844
);
 
845
.fi
 
846
.if n \{\
 
847
.RE
 
848
.\}
 
849
.PP
 
850
Define two
 
851
NOT NULL
 
852
column constraints on the table
 
853
distributors, one of which is explicitly given a name:
 
854
.sp
 
855
.if n \{\
 
856
.RS 4
 
857
.\}
 
858
.nf
 
859
CREATE TABLE distributors (
 
860
    did     integer CONSTRAINT no_null NOT NULL,
 
861
    name    varchar(40) NOT NULL
 
862
);
 
863
.fi
 
864
.if n \{\
 
865
.RE
 
866
.\}
 
867
.PP
 
868
Define a unique constraint for the
 
869
name
 
870
column:
 
871
.sp
 
872
.if n \{\
 
873
.RS 4
 
874
.\}
 
875
.nf
 
876
CREATE TABLE distributors (
 
877
    did     integer,
 
878
    name    varchar(40) UNIQUE
 
879
);
 
880
.fi
 
881
.if n \{\
 
882
.RE
 
883
.\}
 
884
.sp
 
885
The same, specified as a table constraint:
 
886
.sp
 
887
.if n \{\
 
888
.RS 4
 
889
.\}
 
890
.nf
 
891
CREATE TABLE distributors (
 
892
    did     integer,
 
893
    name    varchar(40),
 
894
    UNIQUE(name)
 
895
);
 
896
.fi
 
897
.if n \{\
 
898
.RE
 
899
.\}
 
900
.PP
 
901
Create the same table, specifying 70% fill factor for both the table and its unique index:
 
902
.sp
 
903
.if n \{\
 
904
.RS 4
 
905
.\}
 
906
.nf
 
907
CREATE TABLE distributors (
 
908
    did     integer,
 
909
    name    varchar(40),
 
910
    UNIQUE(name) WITH (fillfactor=70)
 
911
)
 
912
WITH (fillfactor=70);
 
913
.fi
 
914
.if n \{\
 
915
.RE
 
916
.\}
 
917
.PP
 
918
Create table
 
919
circles
 
920
with an exclusion constraint that prevents any two circles from overlapping:
 
921
.sp
 
922
.if n \{\
 
923
.RS 4
 
924
.\}
 
925
.nf
 
926
CREATE TABLE circles (
 
927
    c circle,
 
928
    EXCLUDE USING gist (c WITH &&)
 
929
);
 
930
.fi
 
931
.if n \{\
 
932
.RE
 
933
.\}
 
934
.PP
 
935
Create table
 
936
cinemas
 
937
in tablespace
 
938
diskvol1:
 
939
.sp
 
940
.if n \{\
 
941
.RS 4
 
942
.\}
 
943
.nf
 
944
CREATE TABLE cinemas (
 
945
        id serial,
 
946
        name text,
 
947
        location text
 
948
) TABLESPACE diskvol1;
 
949
.fi
 
950
.if n \{\
 
951
.RE
 
952
.\}
 
953
.PP
 
954
Create a composite type and a typed table:
 
955
.sp
 
956
.if n \{\
 
957
.RS 4
 
958
.\}
 
959
.nf
 
960
CREATE TYPE employee_type AS (name text, salary numeric);
 
961
 
 
962
CREATE TABLE employees OF employee_type (
 
963
    PRIMARY KEY (name),
 
964
    salary WITH OPTIONS DEFAULT 1000
 
965
);
 
966
.fi
 
967
.if n \{\
 
968
.RE
 
969
.\}
 
970
.SH "COMPATIBILITY"
 
971
.PP
 
972
The
 
973
CREATE TABLE
 
974
command conforms to the
 
975
SQL
 
976
standard, with exceptions listed below\&.
 
977
.SS "Temporary Tables"
 
978
.PP
 
979
Although the syntax of
 
980
CREATE TEMPORARY TABLE
 
981
resembles that of the SQL standard, the effect is not the same\&. In the standard, temporary tables are defined just once and automatically exist (starting with empty contents) in every session that needs them\&.
 
982
PostgreSQL
 
983
instead requires each session to issue its own
 
984
CREATE TEMPORARY TABLE
 
985
command for each temporary table to be used\&. This allows different sessions to use the same temporary table name for different purposes, whereas the standard\(aqs approach constrains all instances of a given temporary table name to have the same table structure\&.
 
986
.PP
 
987
The standard\(aqs definition of the behavior of temporary tables is widely ignored\&.
 
988
PostgreSQL\(aqs behavior on this point is similar to that of several other SQL databases\&.
 
989
.PP
 
990
The standard\(aqs distinction between global and local temporary tables is not in
 
991
PostgreSQL, since that distinction depends on the concept of modules, which
 
992
PostgreSQL
 
993
does not have\&. For compatibility\(aqs sake,
 
994
PostgreSQL
 
995
will accept the
 
996
GLOBAL
 
997
and
 
998
LOCAL
 
999
keywords in a temporary table declaration, but they have no effect\&.
 
1000
.PP
 
1001
The
 
1002
ON COMMIT
 
1003
clause for temporary tables also resembles the SQL standard, but has some differences\&. If the
 
1004
ON COMMIT
 
1005
clause is omitted, SQL specifies that the default behavior is
 
1006
ON COMMIT DELETE ROWS\&. However, the default behavior in
 
1007
PostgreSQL
 
1008
is
 
1009
ON COMMIT PRESERVE ROWS\&. The
 
1010
ON COMMIT DROP
 
1011
option does not exist in SQL\&.
 
1012
.SS "Non\-deferred Uniqueness Constraints"
 
1013
.PP
 
1014
When a
 
1015
UNIQUE
 
1016
or
 
1017
PRIMARY KEY
 
1018
constraint is not deferrable,
 
1019
PostgreSQL
 
1020
checks for uniqueness immediately whenever a row is inserted or modified\&. The SQL standard says that uniqueness should be enforced only at the end of the statement; this makes a difference when, for example, a single command updates multiple key values\&. To obtain standard\-compliant behavior, declare the constraint as
 
1021
DEFERRABLE
 
1022
but not deferred (i\&.e\&.,
 
1023
INITIALLY IMMEDIATE)\&. Be aware that this can be significantly slower than immediate uniqueness checking\&.
 
1024
.SS "Column Check Constraints"
 
1025
.PP
 
1026
The SQL standard says that
 
1027
CHECK
 
1028
column constraints can only refer to the column they apply to; only
 
1029
CHECK
 
1030
table constraints can refer to multiple columns\&.
 
1031
PostgreSQL
 
1032
does not enforce this restriction; it treats column and table check constraints alike\&.
 
1033
.SS "EXCLUDE Constraint"
 
1034
.PP
 
1035
The
 
1036
EXCLUDE
 
1037
constraint type is a
 
1038
PostgreSQL
 
1039
extension\&.
 
1040
.SS "NULL \(lqConstraint\(rq"
 
1041
.PP
 
1042
The
 
1043
NULL\(lqconstraint\(rq
 
1044
(actually a non\-constraint) is a
 
1045
PostgreSQL
 
1046
extension to the SQL standard that is included for compatibility with some other database systems (and for symmetry with the
 
1047
NOT NULL
 
1048
constraint)\&. Since it is the default for any column, its presence is simply noise\&.
 
1049
.SS "Inheritance"
 
1050
.PP
 
1051
Multiple inheritance via the
 
1052
INHERITS
 
1053
clause is a
 
1054
PostgreSQL
 
1055
language extension\&. SQL:1999 and later define single inheritance using a different syntax and different semantics\&. SQL:1999\-style inheritance is not yet supported by
 
1056
PostgreSQL\&.
 
1057
.SS "Zero\-column Tables"
 
1058
.PP
 
1059
PostgreSQL
 
1060
allows a table of no columns to be created (for example,
 
1061
CREATE TABLE foo();)\&. This is an extension from the SQL standard, which does not allow zero\-column tables\&. Zero\-column tables are not in themselves very useful, but disallowing them creates odd special cases for
 
1062
ALTER TABLE DROP COLUMN, so it seems cleaner to ignore this spec restriction\&.
 
1063
.SS "WITH Clause"
 
1064
.PP
 
1065
The
 
1066
WITH
 
1067
clause is a
 
1068
PostgreSQL
 
1069
extension; neither storage parameters nor OIDs are in the standard\&.
 
1070
.SS "Tablespaces"
 
1071
.PP
 
1072
The
 
1073
PostgreSQL
 
1074
concept of tablespaces is not part of the standard\&. Hence, the clauses
 
1075
TABLESPACE
 
1076
and
 
1077
USING INDEX TABLESPACE
 
1078
are extensions\&.
 
1079
.SS "Typed Tables"
 
1080
.PP
 
1081
Typed tables implement a subset of the SQL standard\&. According to the standard, a typed table has columns corresponding to the underlying composite type as well as one other column that is the
 
1082
\(lqself\-referencing column\(rq\&. PostgreSQL does not support these self\-referencing columns explicitly, but the same effect can be had using the OID feature\&.
 
1083
.SH "SEE ALSO"
 
1084
ALTER TABLE (\fBALTER_TABLE\fR(7)), DROP TABLE (\fBDROP_TABLE\fR(7)), CREATE TABLESPACE (\fBCREATE_TABLESPACE\fR(7)), CREATE TYPE (\fBCREATE_TYPE\fR(7))