Thread: create table

create table

From
LeoDeBeo
Date:
can anybody explain me the syntax of Create Table documentation??

CREATE [ TEMPORARY | TEMP ] TABLE table (       column type       [ NULL | NOT NULL ] [ UNIQUE ] [ DEFAULT value ]
[ column_constraint_clause | PRIMARY KEY } [ ... ] ]       [ , ... ]       [ , PRIMARY  KEY ( column [, ... ] ) ]
[, CHECK (condition) ]       [ , table_constraint_clause ]       ) [ INHERITS ( inherited_table [, ... ] ) ]
 

i don't understand what the curly brace means after PRIMARY KEY (where is 
the other matching brace? ). It must have something to do with the fact 
that a 'column type' pair ( with options ) can occur more than once, but is 
this syntax right?
i also don't understand what the [ ... ] and [, ... ] means. I do know that 
brackets denote options and | alternatives.

tx




Re: create table

From
Tom Lane
Date:
LeoDeBeo <leodebeo@hotmail.com> writes:
> i don't understand what the curly brace means after PRIMARY KEY (where is 
> the other matching brace?

Typo.  Try more recent versions of the docs.  7.1 says



CREATE [ TEMPORARY | TEMP ] TABLE table_name (   { column_name type [ column_constraint [ ... ] ]     |
table_constraint}  [, ... ]   ) [ INHERITS ( inherited_table [, ... ] ) ]
 

where column_constraint can be:
[ CONSTRAINT constraint_name ]
{ NOT NULL | NULL | UNIQUE | PRIMARY KEY | DEFAULT value | CHECK (condition) | REFERENCES table [ ( column ) ] [ MATCH
FULL| MATCH PARTIAL ]  [ ON DELETE action ] [ ON UPDATE action ]  [ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED
|INITIALLY IMMEDIATE ]
 
}

and table_constraint can be:
[ CONSTRAINT constraint_name ]
{ UNIQUE ( column_name [, ... ] ) | PRIMARY KEY ( column_name [, ... ] ) | CHECK ( condition ) | FOREIGN KEY (
column_name[, ... ] ) REFERENCES table [ ( column [, ... ] ) ]  [ MATCH FULL | MATCH PARTIAL ] [ ON DELETE action ] [
ONUPDATE action ]  [ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ]
 
} 


The curly braces are just for grouping in cases where it'd not be clear
how far the alternatives are supposed to extend.
        regards, tom lane


Re: create table

From
Joel Burton
Date:
On Sun, 29 Apr 2001, LeoDeBeo wrote:

> can anybody explain me the syntax of Create Table documentation??

This doc is much improved in the more recent PG create table help.

Check out the online 7.1 Reference Manual, and there's a much nicer CREATE
TABLE grammar.

-- 
Joel Burton   <jburton@scw.org>
Director of Information Systems, Support Center of Washington



Re: create table

From
Martín Marqués
Date:
On Dom 29 Abr 2001 22:34, LeoDeBeo wrote:
> can anybody explain me the syntax of Create Table documentation??
>
> CREATE [ TEMPORARY | TEMP ] TABLE table (
>         column type
>         [ NULL | NOT NULL ] [ UNIQUE ] [ DEFAULT value ]
>         [ column_constraint_clause | PRIMARY KEY } [ ... ] ]
>         [ , ... ]
>         [ , PRIMARY  KEY ( column [, ... ] ) ]
>         [ , CHECK (condition) ]
>         [ , table_constraint_clause ]
>         ) [ INHERITS ( inherited_table [, ... ] ) ]
>
> i don't understand what the curly brace means after PRIMARY KEY (where is
> the other matching brace? ). It must have something to do with the fact
> that a 'column type' pair ( with options ) can occur more than once, but is
> this syntax right?
> i also don't understand what the [ ... ] and [, ... ] means. I do know that
> brackets denote options and | alternatives.

My docs (7.1) look like this:

CREATE [ TEMPORARY | TEMP ] TABLE table_name (   { column_name type [ column_constraint [ ... ] ]     |
table_constraint}  [, ... ]   ) [ INHERITS ( inherited_table [, ... ] ) ]
 

where column_constraint can be:
[ CONSTRAINT constraint_name ]
{ NOT NULL | NULL | UNIQUE | PRIMARY KEY | DEFAULT value | CHECK (condition) | REFERENCES table [ ( column ) ] [ MATCH
FULL| MATCH PARTIAL ]  [ ON DELETE action ] [ ON UPDATE action ]  [ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED
|INITIALLY IMMEDIATE 
 
]
}

and table_constraint can be:
[ CONSTRAINT constraint_name ]
{ UNIQUE ( column_name [, ... ] ) | PRIMARY KEY ( column_name [, ... ] ) | CHECK ( condition ) | FOREIGN KEY (
column_name[, ... ] ) REFERENCES table [ ( column [, ... ] ) 
 
]  [ MATCH FULL | MATCH PARTIAL ] [ ON DELETE action ] [ ON UPDATE action ]  [ DEFERRABLE | NOT DEFERRABLE ] [
INITIALLYDEFERRED | INITIALLY IMMEDIATE 
 
]
}

Looks clear to me. :-)

-- 
El mejor sistema operativo es aquel que te da de comer.
Cuida tu dieta.
-----------------------------------------------------------------
Martin Marques                  |        mmarques@unl.edu.ar
Programador, Administrador      |       Centro de Telematica                      Universidad Nacional
        del Litoral
 
-----------------------------------------------------------------


Re: create table

From
"Albert REINER"
Date:
On Sun, Apr 29, 2001 at 09:34:29PM +0200, LeoDeBeo wrote:
> can anybody explain me the syntax of Create Table documentation??
...
> i also don't understand what the [ ... ] and [, ... ] means. I do know that 
> brackets denote options and | alternatives.

I guess:
``[ ... ]'' means that you may repeat the clause, and
``[, ... ]'' means that you may repeat the clause, using a comma for separation

Albert.