1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
<!-- manual page source format generated by PolyglotMan v3.0.4, -->
<!-- available via anonymous ftp from ftp.cs.berkeley.edu:/ucb/people/phelps/tcltk/rman.tar.Z -->
<HTML>
<HEAD>
<TITLE>"CREATE(TABLE") manual page</TITLE>
</HEAD>
<BODY>
<A HREF="sql.html">SQL Reference Contents</A>
<H2><A NAME="sect0" HREF="#toc0">NAME </A></H2>
create table - create a new class
<H2><A NAME="sect1" HREF="#toc1">SYNOPSIS </A></H2>
<B>create table </B> classname
<B>( </B>attname type [<B>default </B> value] [<B>not null </B>] <BR>
<tt> </tt><tt> </tt>[<B>, </B> attname type [<B>default
</B> value] [<B>not null </B>] [, ...] ]<B> ) </B> <BR>
<tt> </tt><tt> </tt>[<B>inherits </B> <B>( </B> classname [<B>, </B> classname]
<B>) </B>] <BR>
<tt> </tt><tt> </tt>[<B>constraint </B> cname <B>check </B> <B>( </B> test <B>) </B> [, <B>check </B> <B>( </B> test <B>) </B> ] ] <BR>
<H2><A NAME="sect2" HREF="#toc2">DESCRIPTION
</A></H2>
<B>Create Table</B> will enter a new class into the current data base. The class
will be `owned' by the user issuing the command. The name of the class is
<I>classname</I> and the attributes are as specified in the list of <I>attname</I>s.
Each attribute is created with the type specified by <I>type</I>. Each type may
be a simple type, a complex type (set) or an array type. Each attribute
may be specified to be non-null and each may have a default value, specified
by the <I>default</I> clause which is the keyword "default" followed by a constant
or expression. <P>
Each array attribute stores arrays that must have the same
number of dimensions but may have different sizes and array index bounds.
An array of dimension <I>n</I> is specified by appending <I>n</I> pairs of square
brackets: att_name type[][]..[] <BR>
N.B. As of Postgres version 6.0, consistant
array dimensions within an attribute are not enforced. This will likely
change in a future release. <P>
The optional <B>inherits</B> clause specifies a collection
of class names from which this class automatically inherits all fields.
If any inherited field name appears more than once, Postgres reports
an error. Postgres automatically allows the created class to inherit functions
on classes above it in the inheritance hierarchy. Inheritance of functions
is done according to the conventions of the Common Lisp Object System
(CLOS). <P>
Each new class <I>classname</I> is automatically created as a type. Therefore,
one or more instances from the class are automatically a type and can
be used in <I>alter <A HREF="table.l.html">table</I>(l)</A>
or other <B>create table</B> statements. See <I><A HREF="pgintro.1.html">pgintro</I>(1)</A>
for a further discussion of this point. <P>
The optional <B>constraint</B> clause
specifies a list of constraints or tests which new or updated entries
must satisfy for an insert or update operation to succeed. Each constraint
must evaluate to a boolean expression. Multiple attributes may be referenced
within a single constraint. <P>
The new class is created as a heap with no
initial data. A class can have no more than 1600 attributes (realistically,
this is limited by the fact that tuple sizes must be less than 8192 bytes),
but this limit may be configured lower at some sites. A class cannot have
the same name as a system catalog class. <P>
<H2><A NAME="sect3" HREF="#toc3">EXAMPLES </A></H2>
-- <BR>
-- Create class emp
with attributes name, sal and bdate <BR>
-- <BR>
create table emp (name char16,
salary float4, bdate abstime) <BR>
-- <BR>
--Create class permemp with pension information
that <BR>
--inherits all fields of emp <BR>
-- <BR>
create table permemp (plan char16)
inherits (emp) <BR>
-- <BR>
--Create class emppay with attributes name and wage with
<BR>
--a default salary and constraints on wage range <BR>
-- <BR>
create table emppay
(name text not null, wage float4 default 10.00) <BR>
constraint empcon check
(wage > 5.30 and wage <= 30.00), check (name <> '') <BR>
-- <BR>
--Create class tictactoe
to store noughts-and-crosses <BR>
--boards as a 2-dimensional array <BR>
-- <BR>
create table
tictactoe (game int4, board char[][]) <BR>
-- <BR>
--Create a class newemp with a
set attribute "manager". A <BR>
--set (complex) attribute may be of the same
type as the <BR>
--relation being defined (as here) or of a different complex
<BR>
--type. The type must exist in the "pg_type" catalog or be <BR>
--the one currently
being defined. <BR>
-- <BR>
create table newemp (name text, manager newemp) <BR>
<H2><A NAME="sect4" HREF="#toc4">SEE
ALSO </A></H2>
drop <A HREF="table.l.html">table(l)</A>
. <P>
<HR><P>
<A NAME="toc"><B>Table of Contents</B></A><P>
<UL>
<LI><A NAME="toc0" HREF="#sect0">NAME</A></LI>
<LI><A NAME="toc1" HREF="#sect1">SYNOPSIS</A></LI>
<LI><A NAME="toc2" HREF="#sect2">DESCRIPTION</A></LI>
<LI><A NAME="toc3" HREF="#sect3">EXAMPLES</A></LI>
<LI><A NAME="toc4" HREF="#sect4">SEE ALSO</A></LI>
</UL>
</BODY></HTML>
|