11.\" This is -*-nroff-*-
22.\" XXX standard disclaimer belongs here....
3- .\" $Header: /cvsroot/pgsql/src/man/Attic/create_table.l,v 1.5 1997/08 /2617:39:30 momjian Exp $
4- .TH "CREATE TABLE" SQL11/05/95 PostgreSQL PostgreSQL
3+ .\" $Header: /cvsroot/pgsql/src/man/Attic/create_table.l,v 1.6 1997/09 /2615:21:27 thomas Exp $
4+ .TH "CREATE TABLE" SQL09/25/97 PostgreSQL
55.SH NAME
66create table\(em create a new class
77.SH SYNOPSIS
88.nf
9- \fB create table \fR classname\fB ( \fP attname-1 type-1 {\fB , \fP attname-i type-i}\fB ) \fP
10- [\fB inherits \fR \fB ( \fR classname-1 {\fB , \fR classname-i}\fB ) \fR ]
9+ \fB create table \fR classname\fB ( \fP attname type [\fB default \fP value] [\fB , \fP attname type\fB default \fP value]\fB ) \fP
10+ [\fB inherits \fR \fB ( \fR classname [\fB , \fR classname]\fB ) \fR ]
11+ [\fB constraint \fR cname\fB check \fR \fB ( \fR test\fB ) \fR [\fB , \fR \fB check \fR test]
1112[\fB archive \fR \fB = \fR archive_mode]
1213[\fB store \fR \fB = \fR \*( lq smgr_name\*( rq ]
1314[\fB arch_store \fR \fB = \fR \*( lq smgr_name\*( rq ]
1415.fi
1516.SH DESCRIPTION
16- .BR " Createtable "
17+ .BR " CreateTable "
1718will enter a new class into the current data base. The class will be
1819\*( lq owned\*( rq by the user issuing the command. The name of the
1920class is
2021.IR classname
2122and the attributes are as specified in the list of
2223.IR attname s.
23- The
24- .IR i th
25- attribute is created with the type specified by
26- .IR type " -i."
24+ Each attribute is created with the type specified by
25+ .IR type " ."
2726Each type may be a simple type, a complex type (set) or an array type.
27+ Each attribute may have a default value, specified by the
28+ .IR default
29+ clause which is the keyword "default" followed by a constant or expression.
2830.PP
2931Each array attribute stores arrays that must have the same number of
3032dimensions but may have different sizes and array index bounds. An
@@ -36,6 +38,8 @@ pairs of square brackets:
3638.nf
3739att_name type[][]..[]
3840.fi
41+ N.B. As of Postgres version 6.0, consistant array dimensions within an
42+ attribute are not enforced. This will likely change in a future release.
3943.PP
4044The optional
4145.BR inherits
@@ -50,14 +54,21 @@ Each new class
5054.IR classname
5155is automatically created as a type. Therefore, one or more instances
5256from the class are automatically a type and can be used in
53- .IR alter table(l)
57+ .IR " alter table" (l)
5458or other
5559.BR " create table"
5660statements. See
5761.IR pgintro (1)
5862for a further discussion of this point.
5963.PP
6064The optional
65+ .BR constraint
66+ clause specifies a list of constraints or tests which new or updated entries
67+ must satisfy for an insert or update operation to succeed. Each constraint
68+ must evaluate to a boolean expression. Multiple attributes may be referenced within
69+ a single constraint.
70+ .PP
71+ The optional
6172.BR store
6273and
6374.BR arch_store
@@ -119,6 +130,14 @@ create table permemp (plan char16) inherits (emp)
119130.fi
120131.nf
121132--
133+ --Create class emppay with attributes name and wage with
134+ --a default salary and constraints on wage range
135+ --
136+ create table emppay (name text not null, wage float4 default 10.00)
137+ constraint empcon check (wage > 5.30 and wage <= 30.00), check (name <> '')
138+ .fi
139+ .nf
140+ --
122141--Create class foo on magnetic disk and archive historical data
123142--
124143create table foo (bar int4) archive = heavy