]> granicus.if.org Git - postgresql/blob - src/man/create_table.l
4bee066f05ab68a39a2b04f9b13cb46e5c09e3dc
[postgresql] / src / man / create_table.l
1 .\" This is -*-nroff-*-
2 .\" XXX standard disclaimer belongs here....
3 .\" $Header: /cvsroot/pgsql/src/man/Attic/create_table.l,v 1.5 1997/08/26 17:39:30 momjian Exp $
4 .TH "CREATE TABLE" SQL 11/05/95 PostgreSQL PostgreSQL
5 .SH NAME
6 create table \(em create a new class
7 .SH SYNOPSIS
8 .nf
9 \fBcreate table \fR classname \fB(\fPattname-1 type-1 {\fB,\fP attname-i type-i}\fB)\fP
10         [\fBinherits\fR \fB(\fR classname-1 {\fB,\fR classname-i} \fB)\fR]
11         [\fBarchive\fR \fB=\fR archive_mode]
12         [\fBstore\fR \fB=\fR \*(lqsmgr_name\*(rq]
13         [\fBarch_store\fR \fB=\fR \*(lqsmgr_name\*(rq]
14 .fi
15 .SH DESCRIPTION
16 .BR "Create table"
17 will enter a new class into the current data base.  The class will be
18 \*(lqowned\*(rq by the user issuing the command.  The name of the
19 class is
20 .IR classname
21 and the attributes are as specified in the list of
22 .IR attname s.
23 The 
24 .IR i th
25 attribute is created with the type specified by
26 .IR type "-i."
27 Each type may be a simple type, a complex type (set) or an array type.
28 .PP
29 Each array attribute stores arrays that must have the same number of
30 dimensions but may have different sizes and array index bounds.  An
31 array of dimension
32 .IR n
33 is specified by appending 
34 .IR n
35 pairs of square brackets:
36 .nf
37 att_name type[][]..[]
38 .fi
39 .PP
40 The optional
41 .BR inherits
42 clause specifies a collection of class names from which this class
43 automatically inherits all fields.  If any inherited field name
44 appears more than once, Postgres reports an error.  Postgres automatically
45 allows the created class to inherit functions on classes above it in
46 the inheritance hierarchy.  Inheritance of functions is done according
47 to the conventions of the Common Lisp Object System (CLOS).
48 .PP
49 Each new class
50 .IR classname 
51 is automatically created as a type.  Therefore, one or more instances
52 from the class are automatically a type and can be used in 
53 .IR alter table(l)
54 or other 
55 .BR "create table"
56 statements.  See 
57 .IR pgintro (1)
58 for a further discussion of this point.
59 .PP
60 The optional
61 .BR store
62 and 
63 .BR arch_store
64 keywords may be used to specify a storage manager to use for the new
65 class.  The released version of Postgres supports only \*(lqmagnetic
66 disk\*(rq as a storage manager name; the research system at UC Berkeley
67 provides additional storage managers.
68 .BR Store
69 controls the location of current data,
70 and
71 .BR arch_store
72 controls the location of historical data.
73 .BR Arch_store
74 may only be specified if
75 .BR archive
76 is also specified.  If either
77 .BR store
78 or
79 .BR arch_store
80 is not declared, it defaults to \*(lqmagnetic disk\*(rq.
81 .PP
82 The new class is created as a heap with no initial data.  A class can
83 have no more than 1600 attributes (realistically, this is limited by the
84 fact that tuple sizes must be less than 8192 bytes), but this limit
85 may be configured lower at some sites.  A class cannot have the same
86 name as a system catalog class.
87 .PP
88 The
89 .BR archive
90 keyword specifies whether historical data is to be saved or discarded.
91 .IR Arch_mode 
92 may be one of:
93 .TP 10n
94 .IR none
95 No historical access is supported.
96 .TP 10n
97 .IR light
98 Historical access is allowed and optimized for light update activity.
99 .TP 10n
100 .IR heavy
101 Historical access is allowed and optimized for heavy update activity.
102 .PP
103 .IR Arch_mode
104 defaults to \*(lqnone\*(rq.  Once the archive status is set, there is
105 no way to change it.  For details of the optimization, see [STON87].
106 .SH EXAMPLES
107 .nf
108 --
109 -- Create class emp with attributes name, sal and bdate
110 --
111 create table emp (name char16, salary float4, bdate abstime)
112 .fi
113 .nf
114 --
115 --Create class permemp with pension information that
116 --inherits all fields of emp 
117 --
118 create table permemp (plan char16) inherits (emp)
119 .fi
120 .nf
121 --
122 --Create class foo on magnetic disk and archive historical data
123 --
124 create table foo (bar int4) archive = heavy
125     store = "magnetic disk"
126 .fi
127 .nf
128 --
129 --Create class tictactoe to store noughts-and-crosses
130 --boards as a 2-dimensional array
131 --
132 create table tictactoe (game int4, board char[][])
133 .fi
134 .nf
135 --
136 --Create a class newemp with a set attribute "manager".  A
137 --set (complex) attribute may be of the same type as the
138 --relation being defined (as here) or of a different complex
139 --type.  The type must exist in the "pg_type" catalog or be
140 --the one currently being defined.
141 --
142 create table newemp (name text, manager newemp)
143 .fi
144 .SH "SEE ALSO"
145 drop table(l).