head	1.131;
access;
symbols
	REL9_0_0:1.128.2.1
	REL9_1_ALPHA1:1.131
	REL9_0_RC1:1.128.2.1
	REL9_0_BETA4:1.128
	REL9_0_STABLE:1.128.0.2
	REL9_0_BETA3:1.128
	REL9_0_BETA2:1.127
	REL7_4_29:1.73.2.2
	REL8_0_25:1.90.4.1
	REL8_1_21:1.96
	REL8_2_17:1.105
	REL8_3_11:1.109
	REL8_4_4:1.114.2.2
	REL9_0_BETA1:1.126
	REL9_0_ALPHA5_BRANCH:1.124.0.2
	REL9_0_ALPHA5:1.124
	REL7_4_28:1.73.2.2
	REL8_0_24:1.90.4.1
	REL8_1_20:1.96
	REL8_2_16:1.105
	REL8_3_10:1.109
	REL8_4_3:1.114.2.1
	REL9_0_ALPHA4:1.121
	REL9_0_ALPHA4_BRANCH:1.121.0.2
	REL8_5_ALPHA3:1.120
	REL8_5_ALPHA3_BRANCH:1.120.0.2
	REL7_4_27:1.73.2.2
	REL8_0_23:1.90.4.1
	REL8_1_19:1.96
	REL8_2_15:1.105
	REL8_3_9:1.109
	REL8_4_2:1.114.2.1
	REL8_5_ALPHA2:1.118
	REL8_5_ALPHA2_BRANCH:1.118.0.2
	REL7_4_26:1.73.2.2
	REL8_0_22:1.90.4.1
	REL8_1_18:1.96
	REL8_2_14:1.105
	REL8_3_8:1.109
	REL8_4_1:1.114
	REL8_5_ALPHA1:1.115
	REL8_5_ALPHA1_BRANCH:1.115.0.2
	REL8_4_STABLE:1.114.0.2
	REL8_4_0:1.114
	REL8_4_RC2:1.114
	REL8_4_RC1:1.114
	REL8_4_BETA2:1.114
	REL8_4_BETA1:1.114
	REL7_4_25:1.73.2.2
	REL8_0_21:1.90.4.1
	REL8_1_17:1.96
	REL8_2_13:1.105
	REL8_3_7:1.109
	REL7_4_24:1.73.2.2
	REL8_0_20:1.90.4.1
	REL8_1_16:1.96
	REL8_2_12:1.105
	REL8_3_6:1.109
	REL7_4_23:1.73.2.2
	REL8_0_19:1.90.4.1
	REL8_1_15:1.96
	REL8_2_11:1.105
	REL8_3_5:1.109
	REL7_4_22:1.73.2.2
	REL8_0_18:1.90.4.1
	REL8_1_14:1.96
	REL8_2_10:1.105
	REL8_3_4:1.109
	REL7_4_21:1.73.2.2
	REL8_0_17:1.90.4.1
	REL8_1_13:1.96
	REL8_2_9:1.105
	REL8_3_3:1.109
	REL7_4_20:1.73.2.2
	REL8_0_16:1.90.4.1
	REL8_1_12:1.96
	REL8_2_8:1.105
	REL8_3_2:1.109
	REL8_2_7:1.105
	REL8_3_1:1.109
	REL8_3_STABLE:1.109.0.2
	REL8_3_0:1.109
	REL8_3_RC2:1.109
	REL7_3_21:1.56.2.1
	REL7_4_19:1.73.2.2
	REL8_0_15:1.90.4.1
	REL8_1_11:1.96
	REL8_2_6:1.105
	REL8_3_RC1:1.109
	REL8_3_BETA4:1.109
	REL8_3_BETA3:1.109
	REL8_3_BETA2:1.109
	REL8_3_BETA1:1.109
	REL7_3_20:1.56.2.1
	REL7_4_18:1.73.2.2
	REL8_0_14:1.90.4.1
	REL8_1_10:1.96
	REL8_2_5:1.105
	REL7_3_19:1.56.2.1
	REL7_4_17:1.73.2.2
	REL8_0_13:1.90.4.1
	REL8_1_9:1.96
	REL8_2_4:1.105
	REL8_0_12:1.90.4.1
	REL8_1_8:1.96
	REL8_2_3:1.105
	REL7_3_18:1.56.2.1
	REL7_4_16:1.73.2.2
	REL8_0_11:1.90.4.1
	REL8_1_7:1.96
	REL8_2_2:1.105
	REL8_0_10:1.90.4.1
	REL8_1_6:1.96
	REL8_2_1:1.105
	REL7_4_15:1.73.2.2
	REL7_3_17:1.56.2.1
	REL8_2_STABLE:1.105.0.2
	REL8_2_0:1.105
	REL8_2_RC1:1.105
	REL8_2_BETA3:1.105
	REL8_2_BETA2:1.105
	REL8_1_5:1.96
	REL8_0_9:1.90.4.1
	REL7_4_14:1.73.2.2
	REL7_3_16:1.56.2.1
	REL8_2_BETA1:1.105
	REL7_3_15:1.56.2.1
	REL7_4_13:1.73.2.2
	REL8_0_8:1.90.4.1
	REL8_1_4:1.96
	REL7_3_14:1.56.2.1
	REL7_4_12:1.73.2.2
	REL8_0_7:1.90.4.1
	REL8_1_3:1.96
	REL7_3_13:1.56.2.1
	REL7_4_11:1.73.2.2
	REL8_0_6:1.90.4.1
	REL8_1_2:1.96
	REL7_3_12:1.56.2.1
	REL7_4_10:1.73.2.2
	REL8_0_5:1.90.4.1
	REL8_1_1:1.96
	REL8_1_STABLE:1.96.0.2
	REL8_1_0:1.96
	REL8_1_0RC1:1.94
	REL8_1_0BETA4:1.94
	REL8_1_0BETA3:1.94
	REL7_3_11:1.56.2.1
	REL7_4_9:1.73.2.2
	REL8_0_4:1.90.4.1
	REL8_1_0BETA2:1.94
	REL8_1_0BETA1:1.94
	REL7_2_8:1.52
	REL7_3_10:1.56.2.1
	REL7_4_8:1.73.2.2
	REL8_0_3:1.90.4.1
	REL8_0_2:1.90.4.1
	REL7_2_7:1.52
	REL7_3_9:1.56.2.1
	REL7_4_7:1.73.2.2
	REL8_0_1:1.90.4.1
	REL8_0_STABLE:1.90.0.4
	REL8_0_0:1.90.0.2
	REL8_0_0RC5:1.90
	REL8_0_0RC4:1.90
	REL8_0_0RC3:1.88
	REL8_0_0RC2:1.88
	REL8_0_0RC1:1.87
	REL8_0_0BETA5:1.86
	REL8_0_0BETA4:1.85
	REL7_4_6:1.73.2.2
	REL7_3_8:1.56.2.1
	REL7_2_6:1.52
	REL8_0_0BETA3:1.84
	REL8_0_0BETA2:1.84
	REL7_2_5:1.52
	REL7_4_5:1.73.2.2
	REL7_3_7:1.56.2.1
	REL7_4_4:1.73.2.2
	REL8_0_0BETA1:1.84
	REL7_4_3:1.73.2.2
	REL7_4_2:1.73.2.2
	REL7_3_6:1.56.2.1
	REL7_4_1:1.73.2.2
	REL7_3_5:1.56.2.1
	REL7_4:1.73.2.2
	REL7_4_RC2:1.73
	REL7_4_STABLE:1.73.0.2
	REL7_4_RC1:1.73
	REL7_4_BETA5:1.72
	REL7_4_BETA4:1.72
	REL7_4_BETA3:1.72
	REL7_4_BETA2:1.70
	WIN32_DEV:1.70.0.2
	REL7_4_BETA1:1.70
	REL7_3_4:1.56.2.1
	REL7_3_2:1.56.2.1
	REL7_2_4:1.52
	REL7_3_STABLE:1.56.0.2
	REL7_2_3:1.52
	REL7_2_STABLE:1.52.0.2
	REL7_2:1.52
	REL7_2_RC2:1.52
	REL7_2_RC1:1.52
	REL7_2_BETA5:1.51
	REL7_2_BETA4:1.50
	REL7_2_BETA3:1.49
	REL7_2_BETA2:1.48
	REL7_2_BETA1:1.48
	REL7_1_2:1.42
	REL7_1_STABLE:1.42.0.2
	REL7_1_BETA:1.36
	REL7_1_BETA3:1.39
	REL7_1_BETA2:1.39
	REL7_1:1.41
	REL7_0_PATCHES:1.29.0.2
	REL7_0:1.29
	REL6_5_PATCHES:1.16.0.2
	REL6_5:1.16
	REL6_4:1.10.0.2;
locks; strict;
comment	@# @;


1.131
date	2010.08.17.04.37.21;	author petere;	state Exp;
branches;
next	1.130;

1.130
date	2010.07.26.01.43.52;	author momjian;	state Exp;
branches;
next	1.129;

1.129
date	2010.07.25.23.21.21;	author rhaas;	state Exp;
branches;
next	1.128;

1.128
date	2010.06.07.02.59.02;	author itagaki;	state Exp;
branches
	1.128.2.1;
next	1.127;

1.127
date	2010.05.13.18.54.18;	author tgl;	state Exp;
branches;
next	1.126;

1.126
date	2010.04.16.02.22.33;	author momjian;	state Exp;
branches;
next	1.125;

1.125
date	2010.04.03.07.23.00;	author petere;	state Exp;
branches;
next	1.124;

1.124
date	2010.04.01.00.18.21;	author momjian;	state Exp;
branches;
next	1.123;

1.123
date	2010.02.27.04.29.44;	author tgl;	state Exp;
branches;
next	1.122;

1.122
date	2010.02.22.23.51.40;	author momjian;	state Exp;
branches;
next	1.121;

1.121
date	2010.01.28.23.21.11;	author petere;	state Exp;
branches;
next	1.120;

1.120
date	2009.12.07.05.22.21;	author tgl;	state Exp;
branches;
next	1.119;

1.119
date	2009.10.27.13.58.28;	author alvherre;	state Exp;
branches;
next	1.118;

1.118
date	2009.10.13.00.53.07;	author tgl;	state Exp;
branches;
next	1.117;

1.117
date	2009.10.12.19.49.24;	author adunstan;	state Exp;
branches;
next	1.116;

1.116
date	2009.09.18.05.00.41;	author petere;	state Exp;
branches;
next	1.115;

1.115
date	2009.07.29.20.56.17;	author tgl;	state Exp;
branches;
next	1.114;

1.114
date	2009.02.12.13.25.33;	author momjian;	state Exp;
branches
	1.114.2.1;
next	1.113;

1.113
date	2009.02.09.20.57.59;	author alvherre;	state Exp;
branches;
next	1.112;

1.112
date	2009.02.02.19.31.38;	author alvherre;	state Exp;
branches;
next	1.111;

1.111
date	2008.11.14.10.22.46;	author petere;	state Exp;
branches;
next	1.110;

1.110
date	2008.05.09.23.32.04;	author tgl;	state Exp;
branches;
next	1.109;

1.109
date	2007.07.17.05.02.00;	author neilc;	state Exp;
branches;
next	1.108;

1.108
date	2007.06.03.17.06.03;	author tgl;	state Exp;
branches;
next	1.107;

1.107
date	2007.02.01.00.28.18;	author momjian;	state Exp;
branches;
next	1.106;

1.106
date	2007.01.31.23.26.03;	author momjian;	state Exp;
branches;
next	1.105;

1.105
date	2006.09.16.00.30.17;	author momjian;	state Exp;
branches;
next	1.104;

1.104
date	2006.07.04.18.07.24;	author tgl;	state Exp;
branches;
next	1.103;

1.103
date	2006.07.02.02.23.17;	author momjian;	state Exp;
branches;
next	1.102;

1.102
date	2006.06.28.22.01.52;	author neilc;	state Exp;
branches;
next	1.101;

1.101
date	2006.06.27.03.43.19;	author momjian;	state Exp;
branches;
next	1.100;

1.100
date	2006.02.19.00.04.26;	author neilc;	state Exp;
branches;
next	1.99;

1.99
date	2006.01.16.20.48.49;	author momjian;	state Exp;
branches;
next	1.98;

1.98
date	2006.01.16.19.53.12;	author momjian;	state Exp;
branches;
next	1.97;

1.97
date	2006.01.16.19.50.03;	author momjian;	state Exp;
branches;
next	1.96;

1.96
date	2005.11.01.21.09.50;	author tgl;	state Exp;
branches;
next	1.95;

1.95
date	2005.10.31.18.13.52;	author momjian;	state Exp;
branches;
next	1.94;

1.94
date	2005.08.13.02.48.18;	author momjian;	state Exp;
branches;
next	1.93;

1.93
date	2005.07.14.06.17.36;	author neilc;	state Exp;
branches;
next	1.92;

1.92
date	2005.02.02.06.35.59;	author neilc;	state Exp;
branches;
next	1.91;

1.91
date	2005.01.22.23.22.17;	author momjian;	state Exp;
branches;
next	1.90;

1.90
date	2005.01.05.18.03.19;	author momjian;	state Exp;
branches
	1.90.4.1;
next	1.89;

1.89
date	2005.01.04.00.39.53;	author tgl;	state Exp;
branches;
next	1.88;

1.88
date	2004.12.13.18.05.10;	author petere;	state Exp;
branches;
next	1.87;

1.87
date	2004.11.27.21.27.07;	author petere;	state Exp;
branches;
next	1.86;

1.86
date	2004.11.05.19.15.51;	author tgl;	state Exp;
branches;
next	1.85;

1.85
date	2004.10.21.21.33.59;	author tgl;	state Exp;
branches;
next	1.84;

1.84
date	2004.08.02.04.25.31;	author tgl;	state Exp;
branches;
next	1.83;

1.83
date	2004.07.12.01.22.53;	author momjian;	state Exp;
branches;
next	1.82;

1.82
date	2004.06.18.06.13.05;	author tgl;	state Exp;
branches;
next	1.81;

1.81
date	2004.05.19.23.10.43;	author momjian;	state Exp;
branches;
next	1.80;

1.80
date	2004.03.22.16.18.50;	author tgl;	state Exp;
branches;
next	1.79;

1.79
date	2004.03.09.16.57.47;	author neilc;	state Exp;
branches;
next	1.78;

1.78
date	2004.03.01.17.58.39;	author neilc;	state Exp;
branches;
next	1.77;

1.77
date	2003.12.01.22.07.58;	author momjian;	state Exp;
branches;
next	1.76;

1.76
date	2003.11.29.19.51.38;	author pgsql;	state Exp;
branches;
next	1.75;

1.75
date	2003.11.14.22.56.11;	author tgl;	state Exp;
branches;
next	1.74;

1.74
date	2003.11.12.04.08.07;	author momjian;	state Exp;
branches;
next	1.73;

1.73
date	2003.11.01.01.56.29;	author petere;	state Exp;
branches
	1.73.2.1;
next	1.72;

1.72
date	2003.09.09.18.28.52;	author tgl;	state Exp;
branches;
next	1.71;

1.71
date	2003.08.31.17.32.22;	author petere;	state Exp;
branches;
next	1.70;

1.70
date	2003.06.12.18.34.06;	author tgl;	state Exp;
branches
	1.70.2.1;
next	1.69;

1.69
date	2003.06.12.07.49.43;	author momjian;	state Exp;
branches;
next	1.68;

1.68
date	2003.05.04.00.03.55;	author tgl;	state Exp;
branches;
next	1.67;

1.67
date	2003.04.22.10.08.08;	author petere;	state Exp;
branches;
next	1.66;

1.66
date	2003.04.14.18.08.58;	author tgl;	state Exp;
branches;
next	1.65;

1.65
date	2003.04.14.15.40.02;	author tgl;	state Exp;
branches;
next	1.64;

1.64
date	2003.04.14.15.24.46;	author tgl;	state Exp;
branches;
next	1.63;

1.63
date	2003.03.25.16.15.39;	author petere;	state Exp;
branches;
next	1.62;

1.62
date	2003.02.19.03.13.25;	author momjian;	state Exp;
branches;
next	1.61;

1.61
date	2003.01.19.00.13.29;	author momjian;	state Exp;
branches;
next	1.60;

1.60
date	2002.12.16.19.08.25;	author tgl;	state Exp;
branches;
next	1.59;

1.59
date	2002.11.21.23.34.43;	author petere;	state Exp;
branches;
next	1.58;

1.58
date	2002.11.11.22.19.20;	author tgl;	state Exp;
branches;
next	1.57;

1.57
date	2002.11.09.23.56.38;	author momjian;	state Exp;
branches;
next	1.56;

1.56
date	2002.09.02.06.20.53;	author momjian;	state Exp;
branches
	1.56.2.1;
next	1.55;

1.55
date	2002.05.18.15.44.47;	author petere;	state Exp;
branches;
next	1.54;

1.54
date	2002.04.23.02.07.16;	author tgl;	state Exp;
branches;
next	1.53;

1.53
date	2002.03.22.19.20.40;	author petere;	state Exp;
branches;
next	1.52;

1.52
date	2002.01.20.22.19.56;	author petere;	state Exp;
branches;
next	1.51;

1.51
date	2002.01.03.06.26.22;	author momjian;	state Exp;
branches;
next	1.50;

1.50
date	2001.12.08.03.24.35;	author thomas;	state Exp;
branches;
next	1.49;

1.49
date	2001.11.18.20.35.02;	author petere;	state Exp;
branches;
next	1.48;

1.48
date	2001.10.22.18.14.47;	author petere;	state Exp;
branches;
next	1.47;

1.47
date	2001.10.09.18.46.00;	author petere;	state Exp;
branches;
next	1.46;

1.46
date	2001.09.13.15.55.24;	author petere;	state Exp;
branches;
next	1.45;

1.45
date	2001.09.03.12.57.49;	author petere;	state Exp;
branches;
next	1.44;

1.44
date	2001.08.10.20.52.24;	author tgl;	state Exp;
branches;
next	1.43;

1.43
date	2001.08.10.18.57.32;	author tgl;	state Exp;
branches;
next	1.42;

1.42
date	2001.05.03.17.50.55;	author tgl;	state Exp;
branches;
next	1.41;

1.41
date	2001.02.04.12.18.08;	author petere;	state Exp;
branches;
next	1.40;

1.40
date	2001.01.12.05.06.40;	author tgl;	state Exp;
branches;
next	1.39;

1.39
date	2001.01.05.06.34.16;	author tgl;	state Exp;
branches;
next	1.38;

1.38
date	2000.12.30.19.00.11;	author petere;	state Exp;
branches;
next	1.37;

1.37
date	2000.12.25.23.15.26;	author petere;	state Exp;
branches;
next	1.36;

1.36
date	2000.10.08.13.22.24;	author petere;	state Exp;
branches;
next	1.35;

1.35
date	2000.10.05.19.48.17;	author momjian;	state Exp;
branches;
next	1.34;

1.34
date	2000.08.24.23.36.29;	author tgl;	state Exp;
branches;
next	1.33;

1.33
date	2000.07.22.04.30.27;	author momjian;	state Exp;
branches;
next	1.32;

1.32
date	2000.07.22.02.39.10;	author momjian;	state Exp;
branches;
next	1.31;

1.31
date	2000.07.14.15.27.14;	author thomas;	state Exp;
branches;
next	1.30;

1.30
date	2000.06.09.01.43.57;	author momjian;	state Exp;
branches;
next	1.29;

1.29
date	2000.05.02.20.02.03;	author thomas;	state Exp;
branches;
next	1.28;

1.28
date	2000.04.15.23.29.58;	author momjian;	state Exp;
branches;
next	1.27;

1.27
date	2000.04.14.22.53.10;	author momjian;	state Exp;
branches;
next	1.26;

1.26
date	2000.04.14.22.23.02;	author momjian;	state Exp;
branches;
next	1.25;

1.25
date	2000.04.14.22.16.01;	author momjian;	state Exp;
branches;
next	1.24;

1.24
date	2000.04.14.22.13.24;	author momjian;	state Exp;
branches;
next	1.23;

1.23
date	2000.04.14.21.44.21;	author momjian;	state Exp;
branches;
next	1.22;

1.22
date	2000.04.13.07.19.27;	author momjian;	state Exp;
branches;
next	1.21;

1.21
date	2000.04.12.04.40.03;	author thomas;	state Exp;
branches;
next	1.20;

1.20
date	2000.04.11.14.43.54;	author momjian;	state Exp;
branches;
next	1.19;

1.19
date	2000.04.08.02.44.55;	author momjian;	state Exp;
branches;
next	1.18;

1.18
date	2000.03.27.17.14.42;	author thomas;	state Exp;
branches;
next	1.17;

1.17
date	99.07.22.15.09.08;	author thomas;	state Exp;
branches;
next	1.16;

1.16
date	99.07.06.17.16.35;	author thomas;	state Exp;
branches;
next	1.15;

1.15
date	99.06.14.07.37.04;	author thomas;	state Exp;
branches;
next	1.14;

1.14
date	99.04.06.15.41.19;	author thomas;	state Exp;
branches;
next	1.13;

1.13
date	99.02.13.03.33.50;	author thomas;	state Exp;
branches;
next	1.12;

1.12
date	99.02.02.03.43.55;	author momjian;	state Exp;
branches;
next	1.11;

1.11
date	98.12.29.02.24.36;	author thomas;	state Exp;
branches;
next	1.10;

1.10
date	98.10.30.19.33.50;	author thomas;	state Exp;
branches;
next	1.9;

1.9
date	98.10.21.05.34.11;	author thomas;	state Exp;
branches;
next	1.8;

1.8
date	98.10.15.05.46.59;	author momjian;	state Exp;
branches;
next	1.7;

1.7
date	98.09.25.13.42.27;	author thomas;	state Exp;
branches;
next	1.6;

1.6
date	98.09.22.15.47.42;	author thomas;	state Exp;
branches;
next	1.5;

1.5
date	98.09.07.15.58.17;	author thomas;	state Exp;
branches;
next	1.4;

1.4
date	98.08.17.16.15.31;	author thomas;	state Exp;
branches;
next	1.3;

1.3
date	98.08.15.07.00.35;	author thomas;	state Exp;
branches;
next	1.2;

1.2
date	98.07.29.06.21.56;	author thomas;	state Exp;
branches;
next	1.1;

1.1
date	98.07.14.03.47.34;	author thomas;	state Exp;
branches;
next	;

1.56.2.1
date	2002.11.21.23.31.57;	author petere;	state Exp;
branches;
next	;

1.70.2.1
date	2003.09.07.04.36.45;	author momjian;	state Exp;
branches;
next	;

1.73.2.1
date	2003.11.12.04.08.14;	author momjian;	state Exp;
branches;
next	1.73.2.2;

1.73.2.2
date	2003.11.14.22.56.25;	author tgl;	state Exp;
branches;
next	;

1.90.4.1
date	2005.01.22.23.23.53;	author momjian;	state Exp;
branches;
next	;

1.114.2.1
date	2009.10.27.14.00.15;	author alvherre;	state Exp;
branches;
next	1.114.2.2;

1.114.2.2
date	2010.05.13.18.54.23;	author tgl;	state Exp;
branches;
next	1.114.2.3;

1.114.2.3
date	2010.06.07.03.01.34;	author itagaki;	state Exp;
branches;
next	;

1.128.2.1
date	2010.08.17.04.37.19;	author petere;	state Exp;
branches;
next	;


desc
@@


1.131
log
@Spell and markup checking
@
text
@<!--
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.130 2010/07/26 01:43:52 momjian Exp $
PostgreSQL documentation
-->

<refentry id="SQL-CREATETABLE">
 <refmeta>
  <refentrytitle>CREATE TABLE</refentrytitle>
  <manvolnum>7</manvolnum>
  <refmiscinfo>SQL - Language Statements</refmiscinfo>
 </refmeta>

 <refnamediv>
  <refname>CREATE TABLE</refname>
  <refpurpose>define a new table</refpurpose>
 </refnamediv>

 <indexterm zone="sql-createtable">
  <primary>CREATE TABLE</primary>
 </indexterm>

 <refsynopsisdiv>
<synopsis>
CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE [ IF NOT EXISTS ] <replaceable class="PARAMETER">table_name</replaceable> ( [
  { <replaceable class="PARAMETER">column_name</replaceable> <replaceable class="PARAMETER">data_type</replaceable> [ DEFAULT <replaceable>default_expr</replaceable> ] [ <replaceable class="PARAMETER">column_constraint</replaceable> [ ... ] ]
    | <replaceable>table_constraint</replaceable>
    | LIKE <replaceable>parent_table</replaceable> [ <replaceable>like_option</replaceable> ... ] }
    [, ... ]
] )
[ INHERITS ( <replaceable>parent_table</replaceable> [, ... ] ) ]
[ WITH ( <replaceable class="PARAMETER">storage_parameter</replaceable> [= <replaceable class="PARAMETER">value</replaceable>] [, ... ] ) | WITH OIDS | WITHOUT OIDS ]
[ ON COMMIT { PRESERVE ROWS | DELETE ROWS | DROP } ]
[ TABLESPACE <replaceable class="PARAMETER">tablespace</replaceable> ]

CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE [ IF NOT EXISTS ] <replaceable class="PARAMETER">table_name</replaceable>
    OF <replaceable class="PARAMETER">type_name</replaceable> [ (
  { <replaceable class="PARAMETER">column_name</replaceable> WITH OPTIONS [ DEFAULT <replaceable>default_expr</replaceable> ] [ <replaceable class="PARAMETER">column_constraint</replaceable> [ ... ] ]
    | <replaceable>table_constraint</replaceable> }
    [, ... ]
) ]
[ WITH ( <replaceable class="PARAMETER">storage_parameter</replaceable> [= <replaceable class="PARAMETER">value</replaceable>] [, ... ] ) | WITH OIDS | WITHOUT OIDS ]
[ ON COMMIT { PRESERVE ROWS | DELETE ROWS | DROP } ]
[ TABLESPACE <replaceable class="PARAMETER">tablespace</replaceable> ]

<phrase>where <replaceable class="PARAMETER">column_constraint</replaceable> is:</phrase>

[ CONSTRAINT <replaceable class="PARAMETER">constraint_name</replaceable> ]
{ NOT NULL |
  NULL |
  CHECK ( <replaceable class="PARAMETER">expression</replaceable> ) |
  UNIQUE <replaceable class="PARAMETER">index_parameters</replaceable> |
  PRIMARY KEY <replaceable class="PARAMETER">index_parameters</replaceable> |
  REFERENCES <replaceable class="PARAMETER">reftable</replaceable> [ ( <replaceable class="PARAMETER">refcolumn</replaceable> ) ] [ MATCH FULL | MATCH PARTIAL | MATCH SIMPLE ]
    [ ON DELETE <replaceable class="parameter">action</replaceable> ] [ ON UPDATE <replaceable class="parameter">action</replaceable> ] }
[ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ]

<phrase>and <replaceable class="PARAMETER">table_constraint</replaceable> is:</phrase>

[ CONSTRAINT <replaceable class="PARAMETER">constraint_name</replaceable> ]
{ CHECK ( <replaceable class="PARAMETER">expression</replaceable> ) |
  UNIQUE ( <replaceable class="PARAMETER">column_name</replaceable> [, ... ] ) <replaceable class="PARAMETER">index_parameters</replaceable> |
  PRIMARY KEY ( <replaceable class="PARAMETER">column_name</replaceable> [, ... ] ) <replaceable class="PARAMETER">index_parameters</replaceable> |
  EXCLUDE [ USING <replaceable class="parameter">index_method</replaceable> ] ( <replaceable class="parameter">exclude_element</replaceable> WITH <replaceable class="parameter">operator</replaceable> [, ... ] ) <replaceable class="parameter">index_parameters</replaceable> [ WHERE ( <replaceable class="parameter">predicate</replaceable> ) ] |
  FOREIGN KEY ( <replaceable class="PARAMETER">column_name</replaceable> [, ... ] ) REFERENCES <replaceable class="PARAMETER">reftable</replaceable> [ ( <replaceable class="PARAMETER">refcolumn</replaceable> [, ... ] ) ]
    [ MATCH FULL | MATCH PARTIAL | MATCH SIMPLE ] [ ON DELETE <replaceable class="parameter">action</replaceable> ] [ ON UPDATE <replaceable class="parameter">action</replaceable> ] }
[ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ]

<phrase>and <replaceable class="PARAMETER">like_option</replaceable> is:</phrase>

{ INCLUDING | EXCLUDING } { DEFAULTS | CONSTRAINTS | INDEXES | STORAGE | COMMENTS | ALL }

<phrase><replaceable class="PARAMETER">index_parameters</replaceable> in <literal>UNIQUE</literal>, <literal>PRIMARY KEY</literal>, and <literal>EXCLUDE</literal> constraints are:</phrase>

[ WITH ( <replaceable class="PARAMETER">storage_parameter</replaceable> [= <replaceable class="PARAMETER">value</replaceable>] [, ... ] ) ]
[ USING INDEX TABLESPACE <replaceable class="PARAMETER">tablespace</replaceable> ]

<phrase><replaceable class="PARAMETER">exclude_element</replaceable> in an <literal>EXCLUDE</literal> constraint is:</phrase>

{ <replaceable class="parameter">column</replaceable> | ( <replaceable class="parameter">expression</replaceable> ) } [ <replaceable class="parameter">opclass</replaceable> ] [ ASC | DESC ] [ NULLS { FIRST | LAST } ]
</synopsis>

 </refsynopsisdiv>

 <refsect1 id="SQL-CREATETABLE-description">
  <title>Description</title>

  <para>
   <command>CREATE TABLE</command> will create a new, initially empty table
   in the current database. The table will be owned by the user issuing the
   command.
  </para>

  <para>
   If a schema name is given (for example, <literal>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, or view
   in the same schema.
  </para>

  <para>
   <command>CREATE TABLE</command> 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.
  </para>

  <para>
   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.
  </para>

  <para>
   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.
  </para>
 </refsect1>

 <refsect1>
  <title>Parameters</title>

  <variablelist>

   <varlistentry>
    <term><literal>TEMPORARY</> or <literal>TEMP</></term>
    <listitem>
     <para>
      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 <literal>ON COMMIT</literal> 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.
     </para>

     <para>
      The <link linkend="autovacuum">autovacuum daemon</link> 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
      <command>ANALYZE</> on the temporary table after it is populated.
     </para>

     <para>
      Optionally, <literal>GLOBAL</literal> or <literal>LOCAL</literal>
      can be written before <literal>TEMPORARY</> or <literal>TEMP</>.
      This makes no difference in <productname>PostgreSQL</>, but see
      <xref linkend="sql-createtable-compatibility"
      endterm="sql-createtable-compatibility-title">.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>IF NOT EXISTS</></term>
    <listitem>
     <para>
      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.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><replaceable class="PARAMETER">table_name</replaceable></term>
    <listitem>
     <para>
      The name (optionally schema-qualified) of the table to be created.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>OF <replaceable class="PARAMETER">type_name</replaceable></literal></term>
    <listitem>
     <para>
      Creates a <firstterm>typed table</firstterm>, 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 <literal>DROP TYPE ... CASCADE</literal>).
     </para>

     <para>
      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 <literal>CREATE TABLE</literal> command.
      But the <literal>CREATE TABLE</literal> command can add defaults
      and constraints to the table and can specify storage parameters.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><replaceable class="PARAMETER">column_name</replaceable></term>
    <listitem>
     <para>
      The name of a column to be created in the new table.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><replaceable class="PARAMETER">data_type</replaceable></term>
    <listitem>
     <para>
      The data type of the column. This can include array
      specifiers. For more information on the data types supported by
      <productname>PostgreSQL</productname>, refer to <xref
      linkend="datatype">.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>DEFAULT
    <replaceable>default_expr</replaceable></literal></term>
    <listitem>
     <para>
      The <literal>DEFAULT</> 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.
     </para>

     <para>
      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.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>INHERITS ( <replaceable>parent_table</replaceable> [, ... ] )</literal></term>
    <listitem>
     <para>
      The optional <literal>INHERITS</> clause specifies a list of
      tables from which the new table automatically inherits all
      columns.
     </para>

     <para>
      Use of <literal>INHERITS</> 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).
     </para>

     <para>
      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.
     </para>

     <para>
      <literal>CHECK</> constraints are merged in essentially the same way as
      columns: if multiple parent tables and/or the new table definition
      contain identically-named <literal>CHECK</> 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 <literal>CHECK</>
      constraint in the new table will never be merged, since a unique name
      will always be chosen for it.
     </para>

     <para>
      Column <literal>STORAGE</> settings are also copied from parent tables.
     </para>

    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>LIKE <replaceable>parent_table</replaceable> [ <replaceable>like_option</replaceable> ... ]</literal></term>
    <listitem>
     <para>
      The <literal>LIKE</literal> clause specifies a table from which
      the new table automatically copies all column names, their data types,
      and their not-null constraints.
     </para>
     <para>
      Unlike <literal>INHERITS</literal>, 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.
     </para>
     <para>
      Default expressions for the copied column definitions will only be
      copied if <literal>INCLUDING DEFAULTS</literal> is specified.  The
      default behavior is to exclude default expressions, resulting in the
      copied columns in the new table having null defaults.
     </para>
     <para>
      Not-null constraints are always copied to the new table.
      <literal>CHECK</literal> constraints will only be copied if
      <literal>INCLUDING CONSTRAINTS</literal> is specified; other types of
      constraints will never be copied. Also, no distinction is made between
      column constraints and table constraints &mdash; when constraints are
      requested, all check constraints are copied.
     </para>
     <para>
      Any indexes on the original table will not be created on the new
      table, unless the <literal>INCLUDING INDEXES</literal> clause is
      specified.
     </para>
     <para>
      <literal>STORAGE</> settings for the copied column definitions will only
      be copied if <literal>INCLUDING STORAGE</literal> is specified.  The
      default behavior is to exclude <literal>STORAGE</> settings, resulting
      in the copied columns in the new table having type-specific default
      settings.  For more on <literal>STORAGE</> settings, see
      <xref linkend="storage-toast">.
     </para>
     <para>
      Comments for the copied columns, constraints, and indexes
      will only be copied if <literal>INCLUDING COMMENTS</literal>
      is specified. The default behavior is to exclude comments, resulting in
      the copied columns and constraints in the new table having no comments.
     </para>
     <para>
      <literal>INCLUDING ALL</literal> is an abbreviated form of
      <literal>INCLUDING DEFAULTS INCLUDING CONSTRAINTS INCLUDING INDEXES INCLUDING STORAGE INCLUDING COMMENTS</literal>.
     </para>
     <para>
      Note also that unlike <literal>INHERITS</literal>, columns and
      constraints copied by <literal>LIKE</> are not merged with similarly
      named columns and constraints.
      If the same name is specified explicitly or in another
      <literal>LIKE</literal> clause, an error is signalled.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>CONSTRAINT <replaceable class="PARAMETER">constraint_name</replaceable></literal></term>
    <listitem>
     <para>
      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 <literal>col must be positive</> 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.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>NOT NULL</></term>
    <listitem>
     <para>
      The column is not allowed to contain null values.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>NULL</></term>
    <listitem>
     <para>
      The column is allowed to contain null values. This is the default.
     </para>

     <para>
      This clause is only provided for compatibility with
      non-standard SQL databases.  Its use is discouraged in new
      applications.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>CHECK ( <replaceable class="PARAMETER">expression</replaceable> )</literal></term>
    <listitem>
     <para>
      The <literal>CHECK</> 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's value only, while an expression
      appearing in a table constraint can reference multiple columns.
     </para>

     <para>
      Currently, <literal>CHECK</literal> expressions cannot contain
      subqueries nor refer to variables other than columns of the
      current row.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>UNIQUE</> (column constraint)</term>
    <term><literal>UNIQUE ( <replaceable class="PARAMETER">column_name</replaceable> [, ... ] )</> (table constraint)</term>

    <listitem>
     <para>
      The <literal>UNIQUE</literal> 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.
     </para>

     <para>
      For the purpose of a unique constraint, null values are not
      considered equal.
     </para>

     <para>
      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.)
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>PRIMARY KEY</> (column constraint)</term>
    <term><literal>PRIMARY KEY ( <replaceable class="PARAMETER">column_name</replaceable> [, ... ] )</> (table constraint)</term>
    <listitem>
     <para>
      The primary key constraint specifies that a column or columns of a table
      can contain only unique (non-duplicate), nonnull values.
      Technically, <literal>PRIMARY KEY</literal> is merely a
      combination of <literal>UNIQUE</> and <literal>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.
     </para>

     <para>
      Only one primary key can be specified for a table, whether as a
      column constraint or a table constraint.
     </para>

     <para>
      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.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry id="SQL-CREATETABLE-EXCLUDE">
    <term><literal>EXCLUDE [ USING <replaceable class="parameter">index_method</replaceable> ] ( <replaceable class="parameter">exclude_element</replaceable> WITH <replaceable class="parameter">operator</replaceable> [, ... ] ) <replaceable class="parameter">index_parameters</replaceable> [ WHERE ( <replaceable class="parameter">predicate</replaceable> ) ]</literal></term>
    <listitem>
     <para>
      The <literal>EXCLUDE</> 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 <literal>TRUE</>.  If all of the
      specified operators test for equality, this is equivalent to a
      <literal>UNIQUE</> 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 <xref linkend="datatype-geometric">) by using the
      <literal>&amp;&amp;</> operator.
     </para>

     <para>
      Exclusion constraints are implemented using
      an index, so each specified operator must be associated with an
      appropriate operator class
      (see <xref linkend="indexes-opclass">) for the index access
      method <replaceable>index_method</>.
      The operators are required to be commutative.
      Each <replaceable class="parameter">exclude_element</replaceable>
      can optionally specify an operator class and/or ordering options;
      these are described fully under
      <xref linkend="sql-createindex">.
     </para>

     <para>
      The access method must support <literal>amgettuple</> (see <xref
      linkend="indexam">); at present this means <acronym>GIN</>
      cannot be used.  Although it's 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't do better.
      So in practice the access method will always be <acronym>GiST</>.
     </para>

     <para>
      The <replaceable class="parameter">predicate</> 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.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>REFERENCES <replaceable class="parameter">reftable</replaceable> [ ( <replaceable class="parameter">refcolumn</replaceable> ) ] [ MATCH <replaceable class="parameter">matchtype</replaceable> ] [ ON DELETE <replaceable class="parameter">action</replaceable> ] [ ON UPDATE <replaceable class="parameter">action</replaceable> ]</literal> (column constraint)</term>

   <term><literal>FOREIGN KEY ( <replaceable class="parameter">column</replaceable> [, ... ] )
    REFERENCES <replaceable class="parameter">reftable</replaceable> [ ( <replaceable class="parameter">refcolumn</replaceable> [, ... ] ) ]
    [ MATCH <replaceable class="parameter">matchtype</replaceable> ]
    [ ON DELETE <replaceable class="parameter">action</replaceable> ]
    [ ON UPDATE <replaceable class="parameter">action</replaceable> ]</literal>
    (table constraint)</term>

    <listitem>
     <para>
      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 <replaceable
      class="parameter">refcolumn</replaceable> is omitted, the
      primary key of the <replaceable class="parameter">reftable</replaceable>
      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.
     </para>

     <para>
      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: <literal>MATCH
      FULL</>, <literal>MATCH PARTIAL</>, and <literal>MATCH
      SIMPLE</literal>, which is also the default.  <literal>MATCH
      FULL</> will not allow one column of a multicolumn foreign key
      to be null unless all foreign key columns are null.
      <literal>MATCH SIMPLE</literal> allows some foreign key columns
      to be null while other parts of the foreign key are not
      null. <literal>MATCH PARTIAL</> is not yet implemented.
     </para>

     <para>
      In addition, when the data in the referenced columns is changed,
      certain actions are performed on the data in this table's
      columns.  The <literal>ON DELETE</literal> clause specifies the
      action to perform when a referenced row in the referenced table is
      being deleted.  Likewise, the <literal>ON UPDATE</literal>
      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
      <literal>NO ACTION</literal> check cannot be deferred, even if
      the constraint is declared deferrable. There are the following possible
      actions for each clause:

      <variablelist>
       <varlistentry>
        <term><literal>NO ACTION</literal></term>
        <listitem>
         <para>
          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.
         </para>
        </listitem>
       </varlistentry>

       <varlistentry>
        <term><literal>RESTRICT</literal></term>
        <listitem>
         <para>
          Produce an error indicating that the deletion or update
          would create a foreign key constraint violation.
          This is the same as <literal>NO ACTION</literal> except that
          the check is not deferrable.
         </para>
        </listitem>
       </varlistentry>

       <varlistentry>
        <term><literal>CASCADE</literal></term>
        <listitem>
         <para>
          Delete any rows referencing the deleted row, or update the
          value of the referencing column to the new value of the
          referenced column, respectively.
         </para>
        </listitem>
       </varlistentry>

       <varlistentry>
        <term><literal>SET NULL</literal></term>
        <listitem>
         <para>
          Set the referencing column(s) to null.
         </para>
        </listitem>
       </varlistentry>

       <varlistentry>
        <term><literal>SET DEFAULT</literal></term>
        <listitem>
         <para>
          Set the referencing column(s) to their default values.
         </para>
        </listitem>
       </varlistentry>
      </variablelist>
     </para>

     <para>
      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.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>DEFERRABLE</literal></term>
    <term><literal>NOT DEFERRABLE</literal></term>
    <listitem>
     <para>
      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 <xref linkend="sql-set-constraints"> command).
      <literal>NOT DEFERRABLE</literal> is the default.
      Currently, only <literal>UNIQUE</>, <literal>PRIMARY KEY</>,
      <literal>EXCLUDE</>, and
      <literal>REFERENCES</> (foreign key) constraints accept this
      clause.  <literal>NOT NULL</> and <literal>CHECK</> constraints are not
      deferrable.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>INITIALLY IMMEDIATE</literal></term>
    <term><literal>INITIALLY DEFERRED</literal></term>
    <listitem>
     <para>
      If a constraint is deferrable, this clause specifies the default
      time to check the constraint.  If the constraint is
      <literal>INITIALLY IMMEDIATE</literal>, it is checked after each
      statement. This is the default.  If the constraint is
      <literal>INITIALLY DEFERRED</literal>, it is checked only at the
      end of the transaction.  The constraint check time can be
      altered with the <xref linkend="sql-set-constraints"> command.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>WITH ( <replaceable class="PARAMETER">storage_parameter</replaceable> [= <replaceable class="PARAMETER">value</replaceable>] [, ... ] )</literal></term>
    <listitem>
     <para>
      This clause specifies optional storage parameters for a table or index;
      see <xref linkend="sql-createtable-storage-parameters"
      endterm="sql-createtable-storage-parameters-title"> for more
      information.  The <literal>WITH</> clause for a
      table can also include <literal>OIDS=TRUE</> (or just <literal>OIDS</>)
      to specify that rows of the new table
      should have OIDs (object identifiers) assigned to them, or
      <literal>OIDS=FALSE</> to specify that the rows should not have OIDs.
      If <literal>OIDS</> is not specified, the default setting depends upon
      the <xref linkend="guc-default-with-oids"> configuration parameter.
      (If the new table inherits from any tables that have OIDs, then
      <literal>OIDS=TRUE</> is forced even if the command says
      <literal>OIDS=FALSE</>.)
     </para>

     <para>
      If <literal>OIDS=FALSE</literal> 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.
     </para>

     <para>
      To remove OIDs from a table after it has been created, use <xref
      linkend="sql-altertable">.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>WITH OIDS</></term>
    <term><literal>WITHOUT OIDS</></term>
    <listitem>
     <para>
      These are obsolescent syntaxes equivalent to <literal>WITH (OIDS)</>
      and <literal>WITH (OIDS=FALSE)</>, respectively.  If you wish to give
      both an <literal>OIDS</> setting and storage parameters, you must use
      the <literal>WITH ( ... )</> syntax; see above.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>ON COMMIT</literal></term>
    <listitem>
     <para>
      The behavior of temporary tables at the end of a transaction
      block can be controlled using <literal>ON COMMIT</literal>.
      The three options are:

      <variablelist>
       <varlistentry>
        <term><literal>PRESERVE ROWS</literal></term>
        <listitem>
         <para>
          No special action is taken at the ends of transactions.
          This is the default behavior.
         </para>
        </listitem>
       </varlistentry>

       <varlistentry>
        <term><literal>DELETE ROWS</literal></term>
        <listitem>
         <para>
          All rows in the temporary table will be deleted at the end
          of each transaction block.  Essentially, an automatic <xref
          linkend="sql-truncate"> is done
          at each commit.
         </para>
        </listitem>
       </varlistentry>

       <varlistentry>
        <term><literal>DROP</literal></term>
        <listitem>
         <para>
          The temporary table will be dropped at the end of the current
          transaction block.
         </para>
        </listitem>
       </varlistentry>
      </variablelist>
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>TABLESPACE <replaceable class="PARAMETER">tablespace</replaceable></literal></term>
    <listitem>
     <para>
      The <replaceable class="PARAMETER">tablespace</replaceable> is the name
      of the tablespace in which the new table is to be created.
      If not specified,
      <xref linkend="guc-default-tablespace"> is consulted, or
      <xref linkend="guc-temp-tablespaces"> if the table is temporary.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>USING INDEX TABLESPACE <replaceable class="PARAMETER">tablespace</replaceable></literal></term>
    <listitem>
     <para>
      This clause allows selection of the tablespace in which the index
      associated with a <literal>UNIQUE</literal>, <literal>PRIMARY
      KEY</literal>, or <literal>EXCLUDE</> constraint will be created.
      If not specified,
      <xref linkend="guc-default-tablespace"> is consulted, or
      <xref linkend="guc-temp-tablespaces"> if the table is temporary.
     </para>
    </listitem>
   </varlistentry>

  </variablelist>

  <refsect2 id="SQL-CREATETABLE-storage-parameters">
   <title id="SQL-CREATETABLE-storage-parameters-title">Storage Parameters</title>

 <indexterm zone="sql-createtable-storage-parameters">
  <primary>storage parameters</primary>
 </indexterm>

   <para>
    The <literal>WITH</> clause can specify <firstterm>storage parameters</>
    for tables, and for indexes associated with a <literal>UNIQUE</literal>,
    <literal>PRIMARY KEY</literal>, or <literal>EXCLUDE</> constraint.
    Storage parameters for
    indexes are documented in <xref linkend="SQL-CREATEINDEX">.
    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
    <literal>toast.</literal>, which can be used to control the behavior of the
    table's secondary <acronym>TOAST</> table, if any
    (see <xref linkend="storage-toast"> for more information about TOAST).
    Note that the TOAST table inherits the
    <literal>autovacuum_*</literal> values from its parent table, if there are
    no <literal>toast.autovacuum_*</literal> settings set.
   </para>

   <variablelist>

   <varlistentry>
    <term><literal>fillfactor</> (<type>integer</>)</term>
    <listitem>
     <para>
      The fillfactor for a table is a percentage between 10 and 100.
      100 (complete packing) is the default.  When a smaller fillfactor
      is specified, <command>INSERT</> 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 <command>UPDATE</>
      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.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>autovacuum_enabled</>, <literal>toast.autovacuum_enabled</literal> (<type>boolean</>)</term>
    <listitem>
     <para>
     Enables or disables the autovacuum daemon on a particular table.
     If true, the autovacuum daemon will initiate a <command>VACUUM</> operation
     on a particular table when the number of updated or deleted tuples exceeds
     <literal>autovacuum_vacuum_threshold</> plus
     <literal>autovacuum_vacuum_scale_factor</> times the number of live tuples
     currently estimated to be in the relation.
     Similarly, it will initiate an <command>ANALYZE</> operation when the
     number of inserted, updated or deleted tuples exceeds
     <literal>autovacuum_analyze_threshold</> plus
     <literal>autovacuum_analyze_scale_factor</> 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 <xref linkend="vacuum-for-wraparound"> for
     more about wraparound prevention.
     Observe that this variable inherits its value from the <xref
     linkend="guc-autovacuum"> setting.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>autovacuum_vacuum_threshold</>, <literal>toast.autovacuum_vacuum_threshold</literal> (<type>integer</>)</term>
    <listitem>
     <para>
     Minimum number of updated or deleted tuples before initiate a
     <command>VACUUM</> operation on a particular table.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>autovacuum_vacuum_scale_factor</>, <literal>toast.autovacuum_vacuum_scale_factor</literal> (<type>float4</>)</term>
    <listitem>
     <para>
     Multiplier for <structfield>reltuples</> to add to
     <literal>autovacuum_vacuum_threshold</>.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>autovacuum_analyze_threshold</> (<type>integer</>)</term>
    <listitem>
     <para>
     Minimum number of inserted, updated, or deleted tuples before initiate an
     <command>ANALYZE</> operation on a particular table.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>autovacuum_analyze_scale_factor</> (<type>float4</>)</term>
    <listitem>
     <para>
     Multiplier for <structfield>reltuples</> to add to
     <literal>autovacuum_analyze_threshold</>.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>autovacuum_vacuum_cost_delay</>, <literal>toast.autovacuum_vacuum_cost_delay</literal> (<type>integer</>)</term>
    <listitem>
     <para>
     Custom <xref linkend="guc-autovacuum-vacuum-cost-delay"> parameter.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>autovacuum_vacuum_cost_limit</>, <literal>toast.autovacuum_vacuum_cost_limit</literal> (<type>integer</>)</term>
    <listitem>
     <para>
     Custom <xref linkend="guc-autovacuum-vacuum-cost-limit"> parameter.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>autovacuum_freeze_min_age</>, <literal>toast.autovacuum_freeze_min_age</literal> (<type>integer</>)</term>
    <listitem>
     <para>
     Custom <xref linkend="guc-vacuum-freeze-min-age"> parameter. Note that
     autovacuum will ignore attempts to set a per-table
     <literal>autovacuum_freeze_min_age</> larger than the half system-wide
     <xref linkend="guc-autovacuum-freeze-max-age"> setting.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>autovacuum_freeze_max_age</>, <literal>toast.autovacuum_freeze_max_age</literal> (<type>integer</>)</term>
    <listitem>
     <para>
     Custom <xref linkend="guc-autovacuum-freeze-max-age"> parameter. Note that
     autovacuum will ignore attempts to set a per-table
     <literal>autovacuum_freeze_max_age</> larger than the system-wide setting
     (it can only be set smaller). Note that while you can set
     <literal>autovacuum_freeze_max_age</> very small, or even zero, this is
     usually unwise since it will force frequent vacuuming.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>autovacuum_freeze_table_age</literal>, <literal>toast.autovacuum_freeze_table_age</literal> (<type>integer</type>)</term>
    <listitem>
     <para>
      Custom <xref linkend="guc-vacuum-freeze-table-age"> parameter.
     </para>
    </listitem>
   </varlistentry>

   </variablelist>

  </refsect2>
 </refsect1>

 <refsect1 id="SQL-CREATETABLE-notes">
  <title>Notes</title>

    <para>
     Using OIDs in new applications is not recommended: where
     possible, using a <literal>SERIAL</literal> or other sequence
     generator as the table's 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 <structfield>oid</> 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 <structfield>tableoid</> and row OID for the
     purpose.
    </para>

    <tip>
     <para>
      The use of <literal>OIDS=FALSE</literal> 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.
     </para>
    </tip>

    <para>
     <productname>PostgreSQL</productname> 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 <xref
     linkend="sql-createindex"> for more information.)
    </para>

    <para>
     Unique constraints and primary keys are not inherited in the
     current implementation.  This makes the combination of
     inheritance and unique constraints rather dysfunctional.
    </para>

    <para>
     A table cannot have more than 1600 columns.  (In practice, the
     effective limit is usually lower because of tuple-length constraints.)
    </para>

 </refsect1>


 <refsect1 id="SQL-CREATETABLE-examples">
  <title>Examples</title>

  <para>
   Create table <structname>films</> and table
   <structname>distributors</>:

<programlisting>
CREATE TABLE films (
    code        char(5) CONSTRAINT firstkey PRIMARY KEY,
    title       varchar(40) NOT NULL,
    did         integer NOT NULL,
    date_prod   date,
    kind        varchar(10),
    len         interval hour to minute
);
</programlisting>

<programlisting>
CREATE TABLE distributors (
     did    integer PRIMARY KEY DEFAULT nextval('serial'),
     name   varchar(40) NOT NULL CHECK (name &lt;&gt; '')
);
</programlisting>
  </para>

  <para>
   Create a table with a 2-dimensional array:

<programlisting>
CREATE TABLE array_int (
    vector  int[][]
);
</programlisting>
  </para>

  <para>
   Define a unique table constraint for the table
   <literal>films</literal>.  Unique table constraints can be defined
   on one or more columns of the table:

<programlisting>
CREATE TABLE films (
    code        char(5),
    title       varchar(40),
    did         integer,
    date_prod   date,
    kind        varchar(10),
    len         interval hour to minute,
    CONSTRAINT production UNIQUE(date_prod)
);
</programlisting>
  </para>

  <para>
   Define a check column constraint:

<programlisting>
CREATE TABLE distributors (
    did     integer CHECK (did &gt; 100),
    name    varchar(40)
);
</programlisting>
  </para>

  <para>
   Define a check table constraint:

<programlisting>
CREATE TABLE distributors (
    did     integer,
    name    varchar(40)
    CONSTRAINT con1 CHECK (did &gt; 100 AND name &lt;&gt; '')
);
</programlisting>
  </para>

  <para>
   Define a primary key table constraint for the table
   <structname>films</>:

<programlisting>
CREATE TABLE films (
    code        char(5),
    title       varchar(40),
    did         integer,
    date_prod   date,
    kind        varchar(10),
    len         interval hour to minute,
    CONSTRAINT code_title PRIMARY KEY(code,title)
);
</programlisting>
  </para>

  <para>
   Define a primary key constraint for table
   <structname>distributors</>.  The following two examples are
   equivalent, the first using the table constraint syntax, the second
   the column constraint syntax:

<programlisting>
CREATE TABLE distributors (
    did     integer,
    name    varchar(40),
    PRIMARY KEY(did)
);
</programlisting>

<programlisting>
CREATE TABLE distributors (
    did     integer PRIMARY KEY,
    name    varchar(40)
);
</programlisting>
  </para>

  <para>
   Assign a literal constant default value for the column
   <literal>name</literal>, arrange for the default value of column
   <literal>did</literal> to be generated by selecting the next value
   of a sequence object, and make the default value of
   <literal>modtime</literal> be the time at which the row is
   inserted:

<programlisting>
CREATE TABLE distributors (
    name      varchar(40) DEFAULT 'Luso Films',
    did       integer DEFAULT nextval('distributors_serial'),
    modtime   timestamp DEFAULT current_timestamp
);
</programlisting>
  </para>

  <para>
   Define two <literal>NOT NULL</> column constraints on the table
   <classname>distributors</classname>, one of which is explicitly
   given a name:

<programlisting>
CREATE TABLE distributors (
    did     integer CONSTRAINT no_null NOT NULL,
    name    varchar(40) NOT NULL
);
</programlisting>
    </para>

    <para>
     Define a unique constraint for the <literal>name</literal> column:

<programlisting>
CREATE TABLE distributors (
    did     integer,
    name    varchar(40) UNIQUE
);
</programlisting>

     The same, specified as a table constraint:

<programlisting>
CREATE TABLE distributors (
    did     integer,
    name    varchar(40),
    UNIQUE(name)
);
</programlisting>
  </para>

  <para>
   Create the same table, specifying 70% fill factor for both the table
   and its unique index:

<programlisting>
CREATE TABLE distributors (
    did     integer,
    name    varchar(40),
    UNIQUE(name) WITH (fillfactor=70)
)
WITH (fillfactor=70);
</programlisting>
  </para>

  <para>
   Create table <structname>circles</> with an exclusion
   constraint that prevents any two circles from overlapping:

<programlisting>
CREATE TABLE circles (
    c circle,
    EXCLUDE USING gist (c WITH &amp;&amp;)
);
</programlisting>
  </para>

  <para>
   Create table <structname>cinemas</> in tablespace <structname>diskvol1</>:

<programlisting>
CREATE TABLE cinemas (
        id serial,
        name text,
        location text
) TABLESPACE diskvol1;
</programlisting>
  </para>

  <para>
   Create a composite type and a typed table:
<programlisting>
CREATE TYPE employee_type AS (name text, salary numeric);

CREATE TABLE employees OF employee_type (
    PRIMARY KEY (name),
    salary WITH OPTIONS DEFAULT 1000
);
</programlisting>
  </para>
 </refsect1>

 <refsect1 id="SQL-CREATETABLE-compatibility">
  <title id="SQL-CREATETABLE-compatibility-title">Compatibility</title>

  <para>
   The <command>CREATE TABLE</command> command conforms to the
   <acronym>SQL</acronym> standard, with exceptions listed below.
  </para>

  <refsect2>
   <title>Temporary Tables</title>

   <para>
    Although the syntax of <literal>CREATE TEMPORARY TABLE</literal>
    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.
    <productname>PostgreSQL</productname> instead
    requires each session to issue its own <literal>CREATE TEMPORARY
    TABLE</literal> 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's approach constrains all instances of a
    given temporary table name to have the same table structure.
   </para>

   <para>
    The standard's definition of the behavior of temporary tables is
    widely ignored.  <productname>PostgreSQL</productname>'s behavior
    on this point is similar to that of several other SQL databases.
   </para>

   <para>
    The standard's distinction between global and local temporary tables
    is not in <productname>PostgreSQL</productname>, since that distinction
    depends on the concept of modules, which
    <productname>PostgreSQL</productname> does not have.
    For compatibility's sake, <productname>PostgreSQL</productname> will
    accept the <literal>GLOBAL</literal> and <literal>LOCAL</literal> keywords
    in a temporary table declaration, but they have no effect.
   </para>

   <para>
    The <literal>ON COMMIT</literal> clause for temporary tables
    also resembles the SQL standard, but has some differences.
    If the <literal>ON COMMIT</> clause is omitted, SQL specifies that the
    default behavior is <literal>ON COMMIT DELETE ROWS</>.  However, the
    default behavior in <productname>PostgreSQL</productname> is
    <literal>ON COMMIT PRESERVE ROWS</literal>.  The <literal>ON COMMIT
    DROP</literal> option does not exist in SQL.
   </para>
  </refsect2>

  <refsect2>
   <title>Non-deferred Uniqueness Constraints</title>

   <para>
    When a <literal>UNIQUE</> or <literal>PRIMARY KEY</> constraint is
    not deferrable, <productname>PostgreSQL</productname> 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
    <literal>DEFERRABLE</> but not deferred (i.e., <literal>INITIALLY
    IMMEDIATE</>).  Be aware that this can be significantly slower than
    immediate uniqueness checking.
   </para>
  </refsect2>

  <refsect2>
   <title>Column Check Constraints</title>

   <para>
    The SQL standard says that <literal>CHECK</> column constraints
    can only refer to the column they apply to; only <literal>CHECK</>
    table constraints can refer to multiple columns.
    <productname>PostgreSQL</productname> does not enforce this
    restriction; it treats column and table check constraints alike.
   </para>
  </refsect2>

  <refsect2>
   <title><literal>EXCLUDE</literal> Constraint</title>

   <para>
    The <literal>EXCLUDE</> constraint type is a
    <productname>PostgreSQL</productname> extension.
   </para>
  </refsect2>

  <refsect2>
   <title><literal>NULL</literal> <quote>Constraint</quote></title>

   <para>
    The <literal>NULL</> <quote>constraint</quote> (actually a
    non-constraint) is a <productname>PostgreSQL</productname>
    extension to the SQL standard that is included for compatibility with some
    other database systems (and for symmetry with the <literal>NOT
    NULL</literal> constraint).  Since it is the default for any
    column, its presence is simply noise.
   </para>
  </refsect2>

  <refsect2>
   <title>Inheritance</title>

   <para>
    Multiple inheritance via the <literal>INHERITS</literal> clause is
    a <productname>PostgreSQL</productname> 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
    <productname>PostgreSQL</productname>.
   </para>
  </refsect2>

  <refsect2>
   <title>Zero-column tables</title>

   <para>
    <productname>PostgreSQL</productname> allows a table of no columns
    to be created (for example, <literal>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 <command>ALTER TABLE
    DROP COLUMN</>, so it seems cleaner to ignore this spec restriction.
   </para>
  </refsect2>

  <refsect2>
   <title><literal>WITH</> clause</title>

   <para>
    The <literal>WITH</> clause is a <productname>PostgreSQL</productname>
    extension; neither storage parameters nor OIDs are in the standard.
   </para>
  </refsect2>

  <refsect2>
   <title>Tablespaces</title>

   <para>
    The <productname>PostgreSQL</productname> concept of tablespaces is not
    part of the standard.  Hence, the clauses <literal>TABLESPACE</literal>
    and <literal>USING INDEX TABLESPACE</literal> are extensions.
   </para>
  </refsect2>

  <refsect2>
   <title>Typed Tables</title>

   <para>
    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 <quote>self-referencing column</quote>.  PostgreSQL does not
    support these self-referencing columns explicitly, but the same
    effect can be had using the OID feature.
   </para>
  </refsect2>
 </refsect1>


 <refsect1>
  <title>See Also</title>

  <simplelist type="inline">
   <member><xref linkend="sql-altertable"></member>
   <member><xref linkend="sql-droptable"></member>
   <member><xref linkend="sql-createtablespace"></member>
   <member><xref linkend="sql-createtype"></member>
  </simplelist>
 </refsect1>
</refentry>
@


1.130
log
@Remove tabs from sgml file.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.129 2010/07/25 23:21:21 rhaas Exp $
d515 1
a515 1
      btree or hash indexes with an exclusion constraint, because this
@


1.129
log
@CREATE TABLE IF NOT EXISTS.

Reviewed by Bernd Helmle.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.128 2010/06/07 02:59:02 itagaki Exp $
d171 3
a173 3
	  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.
@


1.128
log
@Ensure default-only storage parameters for TOAST relations
to be initialized with proper values. Affected parameters are
fillfactor, analyze_threshold, and analyze_scale_factor.

Especially uninitialized fillfactor caused inefficient page usage
because we built a StdRdOptions struct in which fillfactor is zero
if any reloption is set for the toast table.

In addition, we disallow toast.autovacuum_analyze_threshold and
toast.autovacuum_analyze_scale_factor because we didn't actually
support them; they are always ignored.

Report by Rumko on pgsql-bugs on 12 May 2010.
Analysis by Tom Lane and Alvaro Herrera. Patch by me.

Backpatch to 8.4.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.127 2010/05/13 18:54:18 tgl Exp $
d24 1
a24 1
CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE <replaceable class="PARAMETER">table_name</replaceable> ( [
d35 1
a35 1
CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE <replaceable class="PARAMETER">table_name</replaceable>
d167 12
@


1.128.2.1
log
@Spell and markup checking
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.128 2010/06/07 02:59:02 itagaki Exp $
d503 1
a503 1
      B-tree or hash indexes with an exclusion constraint, because this
@


1.127
log
@Use "TOAST table" in place of the vague, not-used-elsewhere phrase
"supplementary storage table".
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.126 2010/04/16 02:22:33 momjian Exp $
d883 1
a883 1
    <term><literal>autovacuum_analyze_threshold</>, <literal>toast.autovacuum_analyze_threshold</literal> (<type>integer</>)</term>
d893 1
a893 1
    <term><literal>autovacuum_analyze_scale_factor</>, <literal>toast.autovacuum_analyze_scale_factor</literal> (<type>float4</>)</term>
@


1.126
log
@Document that autovacuum cannot vacuum or analyze temporary tables.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.125 2010/04/03 07:23:00 petere Exp $
d155 1
a155 1
      
d806 2
a807 1
    indexes are documented in <xref linkend="SQL-CREATEINDEX">.  The storage parameters currently
d809 6
a814 5
    there is an additional, identically named parameter, prefixed with
    <literal>toast.</literal> which can be used to control the behavior of the
    supplementary storage table, if any; see <xref linkend="storage-toast">.
    Note that the supplementary storage table inherits the
    <literal>autovacuum</literal> values from its parent table, if there are
d833 1
a833 2
      appropriate.  This parameter cannot be set for the supplementary
      storage table.
@


1.125
log
@Remove unnecessary xref endterm attributes and title ids

The endterm attribute is mainly useful when the toolchain does not support
automatic link target text generation for a particular situation.  In  the
past, this was required by the man page tools for all reference page links,
but that is no longer the case, and it now actually gets in the way of
proper automatic link text generation.  The only remaining use cases are
currently xrefs to refsects.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.124 2010/04/01 00:18:21 momjian Exp $
d148 9
@


1.124
log
@Improve 9.0 release notes by removing extra parentheses and linking to a
more appropriate place for exclusion constraints.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.123 2010/02/27 04:29:44 tgl Exp $
d8 1
a8 1
  <refentrytitle id="sql-createtable-title">CREATE TABLE</refentrytitle>
d487 1
a487 1
      <xref linkend="sql-createindex" endterm="sql-createindex-title">.
d633 1
a633 1
      (using the <xref linkend="sql-set-constraints" endterm="sql-set-constraints-title"> command).
d655 1
a655 1
      altered with the <xref linkend="sql-set-constraints" endterm="sql-set-constraints-title"> command.
d693 1
a693 1
      linkend="sql-altertable" endterm="sql-altertable-title">.
d736 1
a736 1
          linkend="sql-truncate" endterm="sql-truncate-title"> is done
d797 1
a797 2
    indexes are documented in <xref linkend="SQL-CREATEINDEX"
    endterm="sql-createindex-title">.  The storage parameters currently
d980 1
a980 1
     linkend="sql-createindex" endterm="sql-createindex-title"> for more information.)
d1382 4
a1385 4
   <member><xref linkend="sql-altertable" endterm="sql-altertable-title"></member>
   <member><xref linkend="sql-droptable" endterm="sql-droptable-title"></member>
   <member><xref linkend="sql-createtablespace" endterm="sql-createtablespace-title"></member>
   <member><xref linkend="sql-createtype" endterm="sql-createtype-title"></member>
@


1.123
log
@Entity-ify a few new uses of literal <, >, and &.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.122 2010/02/22 23:51:40 momjian Exp $
d458 1
a458 1
   <varlistentry>
@


1.122
log
@Remove long-commented-out paragraph in documentation about function
inheritance in create table, per Andrew Dunstan.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.121 2010/01/28 23:21:11 petere Exp $
d474 1
a474 1
      <literal>&&</> operator.
d1186 1
a1186 1
    EXCLUDE USING gist (c WITH &&)
@


1.121
log
@Type table feature

This adds the CREATE TABLE name OF type command, per SQL standard.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.120 2009/12/07 05:22:21 tgl Exp $
a276 13
<!--
     <para>
      <productname>PostgreSQL</> automatically allows the
     created table to inherit
      functions on tables above it in the inheritance hierarchy; that
      is, if we create table <literal>foo</literal> inheriting from
      <literal>bar</literal>, then functions that accept the tuple
      type <literal>bar</literal> can also be applied to instances of
      <literal>foo</literal>.  (Currently, this works reliably for
      functions on the first or only parent table, but not so well for
      functions on additional parents.)
     </para>
-->
@


1.120
log
@Add exclusion constraints, which generalize the concept of uniqueness to
support any indexable commutative operator, not just equality.  Two rows
violate the exclusion constraint if "row1.col OP row2.col" is TRUE for
each of the columns in the constraint.

Jeff Davis, reviewed by Robert Haas
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.119 2009/10/27 13:58:28 alvherre Exp $
d35 10
d167 21
d1216 11
d1376 13
d1399 1
@


1.119
log
@Fix documentation on the toast.fillfactor reloption: it doesn't exist.

Per note from Zoltan Boszormenyi.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.118 2009/10/13 00:53:07 tgl Exp $
d27 1
a27 1
    | LIKE <replaceable>parent_table</replaceable> [ { INCLUDING | EXCLUDING } { DEFAULTS | CONSTRAINTS | INDEXES | STORAGE | COMMENTS | ALL } ] ... }
d40 1
a42 1
  CHECK ( <replaceable class="PARAMETER">expression</replaceable> ) |
d50 2
a51 1
{ UNIQUE ( <replaceable class="PARAMETER">column_name</replaceable> [, ... ] ) <replaceable class="PARAMETER">index_parameters</replaceable> |
d53 1
a53 1
  CHECK ( <replaceable class="PARAMETER">expression</replaceable> ) |
d58 5
a62 1
<phrase><replaceable class="PARAMETER">index_parameters</replaceable> in <literal>UNIQUE</literal> and <literal>PRIMARY KEY</literal> constraints are:</phrase>
d66 4
d263 1
a263 1
    <term><literal>LIKE <replaceable>parent_table</replaceable> [ { INCLUDING | EXCLUDING } { DEFAULTS | CONSTRAINTS | INDEXES | STORAGE | COMMENTS | ALL } ]</literal></term>
d363 23
d441 1
a441 1
    <term><literal>CHECK ( <replaceable class="PARAMETER">expression</replaceable> )</literal></term>
d444 35
a478 9
      The <literal>CHECK</> 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's value only, while an expression
      appearing in a table constraint can reference multiple columns.
d482 3
a484 3
      Currently, <literal>CHECK</literal> expressions cannot contain
      subqueries nor refer to variables other than columns of the
      current row.
a488 1

d617 2
a618 1
      Currently, only <literal>UNIQUE</>, <literal>PRIMARY KEY</>, and
d756 2
a757 2
      associated with a <literal>UNIQUE</literal> or <literal>PRIMARY
      KEY</literal> constraint will be created.
d776 3
a778 2
    for tables, and for indexes associated with a <literal>UNIQUE</literal> or
    <literal>PRIMARY KEY</literal> constraint.  Storage parameters for
d1162 12
d1269 9
@


1.118
log
@Code review for LIKE INCLUDING patch --- clean up some cosmetic and not
so cosmetic stuff.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.117 2009/10/12 19:49:24 adunstan Exp $
d722 2
a723 2
    available for tables are listed below.  For each parameter, there is an
    additional, identically named parameter, prefixed with
d734 1
a734 1
    <term><literal>fillfactor</>, <literal>toast.fillfactor</literal> (<type>integer</>)</term>
d746 2
a747 1
      appropriate.
d861 1
a861 1
    <term><literal>autovacuum_freeze_table_age</literal> (<type>integer</type>)</term>
@


1.117
log
@CREATE LIKE INCLUDING COMMENTS and STORAGE, and INCLUDING ALL shortcut. Itagaki Takahiro.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.116 2009/09/18 05:00:41 petere Exp $
d234 1
a234 1
      Column storage parameters are also copied from parent tables.
d288 6
a293 5
      Storage parameters for the copied column definitions will only be copied
      if <literal>INCLUDING STORAGE</literal> is specified.  The default
      behavior is to exclude storage parameters, resulting in the copied
      columns in the new table having type-specific default parameters.  For
      more on storage parameters, see <xref linkend="storage-toast">.
d296 4
a299 4
      Comments for the copied column, constraint, index and columns of index
	  definitions will only be copied if <literal>INCLUDING COMMENTS</literal>
	  is specified. The default behavior is to exclude comments, resulting in
	  the copied columns and constraints in the new table having no comments.
d306 3
a308 2
      Note also that unlike <literal>INHERITS</literal>, copied columns and
      constraints are not merged with similarly named columns and constraints.
d757 3
a759 3
     on a particular table when the number of updated or deleted tuples exceeds 
     <literal>autovacuum_vacuum_threshold</> plus 
     <literal>autovacuum_vacuum_scale_factor</> times the number of live tuples 
d763 2
a764 2
     <literal>autovacuum_analyze_threshold</> plus 
     <literal>autovacuum_analyze_scale_factor</> times the number of live tuples 
d780 1
a780 1
     <command>VACUUM</> operation on a particular table. 
d839 1
a839 1
     <literal>autovacuum_freeze_min_age</> larger than the half system-wide 
@


1.116
log
@Easier to translate psql help

Instead of requiring translators to translate the entire SQL command
synopses, change create_help.pl to only require them to translate the
placeholders, and paste those into the synopsis using a printf mechanism.
Make some small updates to the markup to make it easier to parse.

Note: This causes msgmerge of gettext 0.17 to segfault.  You will need
the patch from https://savannah.gnu.org/bugs/?27474 to make it work.
msgmerge usually only runs on babel.postgresql.org, however.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.115 2009/07/29 20:56:17 tgl Exp $
d27 1
a27 1
    | LIKE <replaceable>parent_table</replaceable> [ { INCLUDING | EXCLUDING } { DEFAULTS | CONSTRAINTS | INDEXES } ] ... }
d233 4
d254 1
a254 1
    <term><literal>LIKE <replaceable>parent_table</replaceable> [ { INCLUDING | EXCLUDING } { DEFAULTS | CONSTRAINTS | INDEXES } ]</literal></term>
d288 17
@


1.115
log
@Support deferrable uniqueness constraints.

The current implementation fires an AFTER ROW trigger for each tuple that
looks like it might be non-unique according to the index contents at the
time of insertion.  This works well as long as there aren't many conflicts,
but won't scale to massive unique-key reassignments.  Improving that case
is a TODO item.

Dean Rasheed
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.114 2009/02/12 13:25:33 momjian Exp $
d25 1
a25 1
  { <replaceable class="PARAMETER">column_name</replaceable> <replaceable class="PARAMETER">data_type</replaceable> [ DEFAULT <replaceable>default_expr</> ] [ <replaceable class="PARAMETER">column_constraint</replaceable> [ ... ] ]
d35 1
a35 1
where <replaceable class="PARAMETER">column_constraint</replaceable> is:
d47 1
a47 1
and <replaceable class="PARAMETER">table_constraint</replaceable> is:
d57 1
a57 1
<replaceable class="PARAMETER">index_parameters</replaceable> in <literal>UNIQUE</> and <literal>PRIMARY KEY</> constraints are:
@


1.114
log
@Remove tabs from SGML.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.113 2009/02/09 20:57:59 alvherre Exp $
d38 2
a39 2
{ NOT NULL | 
  NULL | 
d426 4
a429 5
      primary key of the <replaceable
      class="parameter">reftable</replaceable> is used.  The
      referenced columns must be the columns of a unique or primary
      key constraint in the referenced table.  Note that foreign key
      constraints cannot be defined between temporary tables and
d536 5
a540 3
      <literal>NOT DEFERRABLE</literal> is the default.  Only foreign
      key constraints currently accept this clause.  All other
      constraint types are not deferrable.
d1145 17
@


1.114.2.1
log
@Fix documentation on the toast.fillfactor reloption: it doesn't exist.

Per note from Zoltan Boszormenyi.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.114 2009-02-12 13:25:33 momjian Exp $
d698 2
a699 2
    available for tables are listed below.  For each parameter, unless noted,
    there is an additional, identically named parameter, prefixed with
d710 1
a710 1
    <term><literal>fillfactor</> (<type>integer</>)</term>
d722 1
a722 2
      appropriate.  This parameter cannot be set for the supplementary
      storage table.
d836 1
a836 1
    <term><literal>autovacuum_freeze_table_age</literal>, <literal>toast.autovacuum_freeze_table_age</literal> (<type>integer</type>)</term>
@


1.114.2.2
log
@Use "TOAST table" in place of the vague, not-used-elsewhere phrase
"supplementary storage table".
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.114.2.1 2009/10/27 14:00:15 alvherre Exp $
d699 5
a703 6
    there is an additional parameter with the same name prefixed with
    <literal>toast.</literal>, which can be used to control the behavior of the
    table's secondary <acronym>TOAST</> table, if any
    (see <xref linkend="storage-toast"> for more information about TOAST).
    Note that the TOAST table inherits the
    <literal>autovacuum_*</literal> values from its parent table, if there are
d722 2
a723 1
      appropriate.  This parameter cannot be set for TOAST tables.
@


1.114.2.3
log
@Ensure default-only storage parameters for TOAST relations
to be initialized with proper values. Affected parameters are
fillfactor, analyze_threshold, and analyze_scale_factor.

Especially uninitialized fillfactor caused inefficient page usage
because we built a StdRdOptions struct in which fillfactor is zero
if any reloption is set for the toast table.

In addition, we disallow toast.autovacuum_analyze_threshold and
toast.autovacuum_analyze_scale_factor because we didn't actually
support them; they are always ignored.

Report by Rumko on pgsql-bugs on 12 May 2010.
Analysis by Tom Lane and Alvaro Herrera. Patch by me.

Backpatch to 8.4.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.114.2.2 2010/05/13 18:54:23 tgl Exp $
d773 1
a773 1
    <term><literal>autovacuum_analyze_threshold</> (<type>integer</>)</term>
d783 1
a783 1
    <term><literal>autovacuum_analyze_scale_factor</> (<type>float4</>)</term>
@


1.113
log
@Update autovacuum to use reloptions instead of a system catalog, for
per-table overrides of parameters.

This removes a whole class of problems related to misusing the catalog,
and perhaps more importantly, gives us pg_dump support for the parameters.

Based on a patch by Euler Taveira de Oliveira, heavily reworked by me.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.112 2009/02/02 19:31:38 alvherre Exp $
d700 1
a700 1
	<literal>toast.</literal> which can be used to control the behavior of the
d702 1
a702 1
	Note that the supplementary storage table inherits the
@


1.112
log
@Allow reloption names to have qualifiers, initially supporting a TOAST
qualifier, and add support for this in pg_dump.

This allows TOAST tables to have user-defined fillfactor, and will also
enable us to move the autovacuum parameters to reloptions without taking
away the possibility of setting values for TOAST tables.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.111 2008/11/14 10:22:46 petere Exp $
d688 4
d698 7
a704 1
    available for tables are:
d710 1
a710 1
    <term><literal>FILLFACTOR</></term>
d728 109
a836 1
    <term><literal>TOAST.FILLFACTOR</literal></term>
d839 1
a839 2
      Same as above, for the supplementary storage table, if any; see
      <xref linkend="storage-toast">.
@


1.111
log
@Set SQL man pages to be section 7 by default, and only transform them to
another section if required by the platform (instead of the old way of
building them in section "l" and always transforming them to the
platform-specific section).

This speeds up the installation on common platforms, and it avoids some
funny business with the man page tools and build process.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.110 2008/05/09 23:32:04 tgl Exp $
d693 2
a694 2
    endterm="sql-createindex-title">.  The only storage parameter currently
    available for tables is:
d717 10
@


1.110
log
@Change the rules for inherited CHECK constraints to be essentially the same
as those for inherited columns; that is, it's no longer allowed for a child
table to not have a check constraint matching one that exists on a parent.
This satisfies the principle of least surprise (rows selected from the parent
will always appear to meet its check constraints) and eliminates some
longstanding bogosity in pg_dump, which formerly had to guess about whether
check constraints were really inherited or not.

The implementation involves adding conislocal and coninhcount columns to
pg_constraint (paralleling attislocal and attinhcount in pg_attribute)
and refactoring various ALTER TABLE actions to be more like those for
columns.

Alex Hunsaker, Nikhil Sontakke, Tom Lane
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.109 2007/07/17 05:02:00 neilc Exp $
d9 1
@


1.109
log
@Implement CREATE TABLE LIKE ... INCLUDING INDEXES. Patch from NikhilS,
based in part on an earlier patch from Trevor Hardcastle, and reviewed
by myself.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.108 2007/06/03 17:06:03 tgl Exp $
d213 1
a213 4
      definitions are merged into one.  However, inherited and new
      column declarations of the same name need not specify identical
      constraints: all constraints provided from any declaration are
      merged together and all are applied to the new table.  If the
d220 12
@


1.108
log
@Create a GUC parameter temp_tablespaces that allows selection of the
tablespace(s) in which to store temp tables and temporary files.  This is a
list to allow spreading the load across multiple tablespaces (a random list
element is chosen each time a temp object is to be created).  Temp files are
not stored in per-database pgsql_tmp/ directories anymore, but per-tablespace
directories.

Jaime Casanova and Albert Cervera, with review by Bernd Helmle and Tom Lane.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.107 2007/02/01 00:28:18 momjian Exp $
d26 1
a26 1
    | LIKE <replaceable>parent_table</replaceable> [ { INCLUDING | EXCLUDING } { DEFAULTS | CONSTRAINTS } ] ... }
d240 1
a240 1
    <term><literal>LIKE <replaceable>parent_table</replaceable> [ { INCLUDING | EXCLUDING } { DEFAULTS | CONSTRAINTS } ]</literal></term>
d269 5
d277 1
a277 1
      <literal>LIKE</literal> clause an error is signalled.
@


1.107
log
@Consistenly use colons before '<programlisting>' blocks, where
appropriate.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.106 2007/01/31 23:26:03 momjian Exp $
d648 2
a649 3
      <xref linkend="guc-default-tablespace"> is used, or the database's
      default tablespace if <varname>default_tablespace</> is an empty
      string.
d662 2
a663 3
      <xref linkend="guc-default-tablespace"> is used, or the database's
      default tablespace if <varname>default_tablespace</> is an empty
      string.
@


1.106
log
@Update reference documentation on may/can/might:

Standard English uses "may", "can", and "might" in different ways:

        may - permission, "You may borrow my rake."

        can - ability, "I can lift that log."

        might - possibility, "It might rain today."

Unfortunately, in conversational English, their use is often mixed, as
in, "You may use this variable to do X", when in fact, "can" is a better
choice.  Similarly, "It may crash" is better stated, "It might crash".
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.105 2006/09/16 00:30:17 momjian Exp $
d795 1
a795 1
   on one or more columns of the table.
@


1.105
log
@Remove emacs info from footer of SGML files.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.104 2006/07/04 18:07:24 tgl Exp $
d77 1
a77 1
   tables exist in a special schema, so a schema name may not be given
d159 1
a159 1
      The data type of the column. This may include array
d322 1
a322 1
      group of one or more columns of a table may contain
d348 1
a348 1
      may contain only unique (non-duplicate), nonnull values.
d354 1
a354 1
      may rely on this set of columns as a unique identifier for rows.
d382 1
a382 1
      appearing in a table constraint may reference multiple columns.
d415 1
a415 1
      constraints may not be defined between temporary tables and
d504 1
a504 1
      If the referenced column(s) are changed frequently, it may be wise to
d520 1
a520 1
      deferrable may be postponed until the end of the transaction
d1008 2
a1009 2
    may only refer to the column they apply to; only <literal>CHECK</>
    table constraints may refer to multiple columns.
@


1.104
log
@Documentation fixes for FILLFACTOR patch.  Minor other editorialization.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.103 2006/07/02 02:23:17 momjian Exp $
a1084 17

<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:nil
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../reference.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:"/usr/lib/sgml/catalog"
sgml-local-ecat-files:nil
End:
-->
@


1.103
log
@Add FILLFACTOR to CREATE INDEX.

ITAGAKI Takahiro
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.102 2006/06/28 22:01:52 neilc Exp $
d30 1
a30 2
[ WITH OIDS | WITHOUT OIDS ]
[ WITH (FILLFACTOR = <replaceable>fillfactor</replaceable>) ]
d39 3
a41 3
  UNIQUE [ USING INDEX TABLESPACE <replaceable class="PARAMETER">tablespace</replaceable> ] |
  PRIMARY KEY [ USING INDEX TABLESPACE <replaceable class="PARAMETER">tablespace</replaceable> ] |
  CHECK (<replaceable class="PARAMETER">expression</replaceable>) |
d49 2
a50 2
{ UNIQUE ( <replaceable class="PARAMETER">column_name</replaceable> [, ... ] ) [ USING INDEX TABLESPACE <replaceable class="PARAMETER">tablespace</replaceable> ] |
  PRIMARY KEY ( <replaceable class="PARAMETER">column_name</replaceable> [, ... ] ) [ USING INDEX TABLESPACE <replaceable class="PARAMETER">tablespace</replaceable> ] |
d55 5
a277 43
    <term><literal>WITH OIDS</></term>
    <term><literal>WITHOUT OIDS</></term>
    <listitem>
     <para>
      This optional clause specifies whether rows of the new table
      should have OIDs (object identifiers) assigned to them.  If
      neither <literal>WITH OIDS</literal> nor <literal>WITHOUT
      OIDS</literal> is specified, the default value depends upon the
      <xref linkend="guc-default-with-oids"> configuration parameter. (If
      the new table inherits from any tables that have OIDs, then
      <literal>WITH OIDS</> is forced even if the command says
      <literal>WITHOUT OIDS</>.)
     </para>

     <para>
      If <literal>WITHOUT OIDS</literal> 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.
     </para>

     <para>
      To remove OIDs from a table after it has been created, use <xref
      linkend="sql-altertable" endterm="sql-altertable-title">.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>WITH (FILLFACTOR = <replaceable>fillfactor</replaceable>)</literal></term>
    <listitem>
     <para>
      This optional clause specifies the table's fillfactor in percentage.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
d371 1
a371 1
    <term><literal>CHECK (<replaceable class="PARAMETER">expression</replaceable>)</literal></term>
d546 51
d671 36
d728 1
a728 1
      The use of <literal>WITHOUT OIDS</literal> is not recommended
d748 4
a751 4
  <para>
   A table cannot have more than 1600 columns.  (In practice, the
   effective limit is lower because of tuple-length constraints.)
  </para>
d835 1
a835 2
   <structname>films</>.  Primary key table constraints can be defined
   on one or more columns of the table.
d854 1
a854 1
   the column constraint syntax.
d873 2
a874 2
   This assigns a literal constant default value for the column
   <literal>name</literal>, arranges for the default value of column
d876 1
a876 1
   of a sequence object, and makes the default value of
d878 1
a878 1
   inserted.
d912 1
a912 1
     The above is equivalent to the following specified as a table constraint:
d924 14
a1041 9
   <title>Object IDs</title>

   <para>
    The <productname>PostgreSQL</productname> concept of OIDs is not
    standard.
   </para>
  </refsect2>

  <refsect2>
d1055 9
@


1.102
log
@Editorialization for the additions to the CREATE TABLE reference page
made as part of the recent INCLUDING CONSTRAINTS patch. The text could
stand further improvement, but this is at least a step in the right
direction.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.101 2006/06/27 03:43:19 momjian Exp $
d31 1
d308 9
@


1.101
log
@Add INCLUDING CONSTRAINTS to CREATE TABLE LIKE.

Greg Stark
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.100 2006/02/19 00:04:26 neilc Exp $
d252 2
a253 2
      default behavior is to exclude default expressions, resulting in
      all columns of the new table having null defaults.
d256 6
a261 6
      Likewise constraints for the copied column definitions will only be
      copied if <literal>INCLUDING CONSTRAINTS</literal> is specified. Note
      that currently even when <literal>INCLUDING CONSTRAINTS</literal> is specified
      only CHECK constraints are copied. Also, no distinction is made between
      column constraints and table constraints -- when constraints are
      requested all check constraints are copied.
d264 1
a264 1
      Note also that unlike <literal>INHERITS<literal> copied columns and
@


1.100
log
@Add TABLESPACE and ON COMMIT clauses to CREATE TABLE AS. ON COMMIT is
required by the SQL standard, and TABLESPACE is useful functionality.
Patch from Kris Jurka, minor editorialization by Neil Conway.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.99 2006/01/16 20:48:49 momjian Exp $
d26 1
a26 1
    | LIKE <replaceable>parent_table</replaceable> [ { INCLUDING | EXCLUDING } DEFAULTS ] }
d235 1
a235 1
    <term><literal>LIKE <replaceable>parent_table</replaceable> [ { INCLUDING | EXCLUDING } DEFAULTS ]</literal></term>
d255 14
@


1.99
log
@Improve constraint_name wording.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.98 2006/01/16 19:53:12 momjian Exp $
d583 4
a586 3
          All rows in the temporary table will be deleted at the
          end of each transaction block.  Essentially, an automatic
          <xref linkend="sql-truncate"> is done at each commit.
@


1.98
log
@Add markup for new constraint_name mention.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.97 2006/01/16 19:50:03 momjian Exp $
d298 1
a298 1
      so constraint names like <literal>"col must be positive"</> can be used
d300 2
a301 2
      (Double-quotes are required for constraint names that contain spaces.)
      If not specified, the system generates a name.
@


1.97
log
@Add documentaiotn mention that constraint names can be sentences that
can convey information to clients on constraint violation.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.96 2005/11/01 21:09:50 tgl Exp $
d298 4
a301 3
      so constraint names like "col must be positive" can be used to communicate
      helpful constraint information to client applications.  If not specified,
      the system generates a name.
@


1.96
log
@Make an editorial pass over the reference pages.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.95 2005/10/31 18:13:52 momjian Exp $
d296 4
a299 1
      An optional name for a column or table constraint.  If not specified,
@


1.95
log
@Mention in the docs that temporary/non-temp tables can not share
referential integrity relationships.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.94 2005/08/13 02:48:18 momjian Exp $
d23 2
a24 2
CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE <replaceable class="PARAMETER">table_name</replaceable> (
  [ <replaceable class="PARAMETER">column_name</replaceable> <replaceable class="PARAMETER">data_type</replaceable> [ DEFAULT <replaceable>default_expr</> ] [ <replaceable class="PARAMETER">column_constraint</replaceable> [ ... ] ]
d26 3
a28 2
    | LIKE <replaceable>parent_table</replaceable> [ { INCLUDING | EXCLUDING } DEFAULTS ] ]  [, ... ]
)
d865 2
a866 2
   The <command>CREATE TABLE</command> command conforms to SQL-92 and
   to a subset of SQL:2003, with exceptions listed below.
d944 2
a945 2
    SQL:2003 defines single inheritance using a
    different syntax and different semantics.  SQL:2003-style
@


1.94
log
@CREATE TABLE has optional column names, so change {} to [].

Alvaro.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.93 2005/07/14 06:17:36 neilc Exp $
d424 3
a426 1
      key constraint in the referenced table.
@


1.93
log
@This doc patch replaces all inappropriate references to SQL:1999 when it
is used as if it were the latest (and/or still valid) SQL standard.
SQL:2003 is used in its place. Patch from Simon Riggs.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.92 2005/02/02 06:35:59 neilc Exp $
d24 1
a24 1
  { <replaceable class="PARAMETER">column_name</replaceable> <replaceable class="PARAMETER">data_type</replaceable> [ DEFAULT <replaceable>default_expr</> ] [ <replaceable class="PARAMETER">column_constraint</replaceable> [ ... ] ]
d26 1
a26 1
    | LIKE <replaceable>parent_table</replaceable> [ { INCLUDING | EXCLUDING } DEFAULTS ] }  [, ... ]
@


1.92
log
@Add support for temporary views, including documentation and regression
tests. Contributed by Koju Iijima, review from Neil Conway, Gavin Sherry
and Tom Lane.

Also, fix error in description of WITH CHECK OPTION clause in the CREATE
VIEW reference page: it should be "CASCADED", not "CASCADE".
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.91 2005/01/22 23:22:17 momjian Exp $
d863 1
a863 1
   to a subset of SQL:1999, with exceptions listed below.
d941 2
a942 2
    SQL:1999 (but not SQL-92) defines single inheritance using a
    different syntax and different semantics.  SQL:1999-style
@


1.91
log
@More < and > changes to ampersands.

8.0.X and HEAD.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.90 2005/01/05 18:03:19 momjian Exp $
d69 6
a74 6
   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 may not be
   given when creating a temporary table.
   The table name must be distinct from the name of any other table,
   sequence, index, or view in the same schema.
@


1.90
log
@Fix example, change table name from 'array' to 'array_int'.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.89 2005/01/04 00:39:53 tgl Exp $
d735 1
a735 1
    did     integer CHECK (did > 100),
d748 1
a748 1
    CONSTRAINT con1 CHECK (did > 100 AND name &lt;&gt; '')
@


1.90.4.1
log
@More < and > changes to ampersands.

8.0.X and HEAD.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.90 2005/01/05 18:03:19 momjian Exp $
d735 1
a735 1
    did     integer CHECK (did &gt; 100),
d748 1
a748 1
    CONSTRAINT con1 CHECK (did &gt; 100 AND name &lt;&gt; '')
@


1.89
log
@More minor updates and copy-editing.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.88 2004/12/13 18:05:10 petere Exp $
d706 1
a706 1
CREATE TABLE array (
@


1.88
log
@Spell checker run
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.87 2004/11/27 21:27:07 petere Exp $
d85 1
a85 6
   A table cannot have more than 1600 columns.  (In practice, the
   effective limit is lower because of tuple-length constraints).
  </para>

  <para>
   The optional constraint clauses specify constraints (or tests) that
d97 1
a97 1
   a column constraint is only a notational convenience if the
d154 1
a154 1
      specifiers. For more information on the data types included with
a182 23
    <term><literal>LIKE <replaceable>parent_table</replaceable> [ { INCLUDING | EXCLUDING } DEFAULTS ]</literal></term>
    <listitem>
     <para>
      The <literal>LIKE</literal> clause specifies a table from which
      the new table automatically copies all column names, their data types,
      and their not-null constraints.
     </para>
     <para>
      Unlike <literal>INHERITS</literal>, 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.
     </para>
     <para>
      Default expressions for the copied column definitions will only be
      included if <literal>INCLUDING DEFAULTS</literal> is specified.  The
      default is to exclude default expressions.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
d234 24
d273 3
a275 3
      If <literal>WITHOUT OIDS</literal> is specified or implied, this
      means that the generation of OIDs for this table will be
      supressed. This is generally considered worthwhile, since it
d280 2
a281 2
      table reduces the space required on disk to storage the table by
      4 bytes per row, leading to increased performance.
d318 1
a318 1
      This clause is only available for compatibility with
d332 1
a332 1
      group of one or more distinct columns of a table may contain
d449 3
a451 3
      changed, no action is done. Referential actions apart from the
      check of <literal>NO ACTION</literal> can not be deferred even if
      the constraint is deferrable. There are the following possible
d475 1
a475 1
	  the check is not deferrable.
a631 2
  <itemizedlist>
   <listitem>
d636 1
a636 1
     your application does make use of OIDs to identify specific rows
a652 1
   </listitem>
a653 1
   <listitem>
d657 2
a658 2
     enforce the uniqueness.  Thus, it is not necessary to create an
     explicit index for primary key columns.  (See <xref
a660 1
   </listitem>
a661 1
   <listitem>
d667 6
a672 2
   </listitem>
  </itemizedlist>
d775 1
a775 1
   the column constraint notation.
@


1.87
log
@Update of conformance information to SQL:2003
by Troels Arvin, Simon Riggs, Elein Mustain

Make spelling of SQL standard names uniform.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.86 2004/11/05 19:15:51 tgl Exp $
d977 1
a977 1
   <title>TABLESPACE and USING INDEX TABLESPACE</title>
d981 2
a982 1
    standard.
@


1.86
log
@Create 'default_tablespace' GUC variable that supplies a TABLESPACE
clause implicitly whenever one is not given explicitly.  Remove concept
of a schema having an associated tablespace, and simplify the rules for
selecting a default tablespace for a table or index.  It's now just
(a) explicit TABLESPACE clause; (b) default_tablespace if that's not an
empty string; (c) database's default.  This will allow pg_dump to use
SET commands instead of tablespace clauses to determine object locations
(but I didn't actually make it do so).  All per recent discussions.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.85 2004/10/21 21:33:59 tgl Exp $
d868 2
a869 2
   The <command>CREATE TABLE</command> command conforms to SQL92
   and to a subset of SQL99, with exceptions listed below.
d946 5
a950 4
    a <productname>PostgreSQL</productname> language extension.  SQL99
    (but not SQL92) defines single inheritance using a different
    syntax and different semantics.  SQL99-style inheritance is not
    yet supported by <productname>PostgreSQL</productname>.
@


1.85
log
@Disallow referential integrity actions from being deferred; only the
NO ACTION check is deferrable.  This seems to be a closer approximation
to what the SQL spec says than what we were doing before, and it prevents
some anomalous behaviors that are possible now that triggers can fire
during the execution of PL functions.
Stephan Szabo.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.84 2004/08/02 04:25:31 tgl Exp $
d606 5
a610 2
      of the tablespace in which the new table is to be created. If not
      supplied, the default tablespace of the table's schema will be used.
d621 5
a625 2
      KEY</literal> constraint will be created.  If not supplied, the index
      will be created in the same tablespace as the table.
@


1.84
log
@Support USING INDEX TABLESPACE clause for PRIMARY KEY and UNIQUE
constraints.  Christopher Kings-Lynne.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql-server/doc/src/sgml/ref/create_table.sgml,v 1.83 2004/07/12 01:22:53 momjian Exp $
d420 1
a420 1
      Theses clauses specify a foreign key constraint, which specifies
d422 2
a423 4
      contain values which match against values in the referenced
      column(s) <replaceable class="parameter">refcolumn</replaceable>
      of the referenced table <replaceable
      class="parameter">reftable</replaceable>.  If <replaceable
d432 1
a432 1
      A value inserted into these columns is matched against the
d453 3
a455 1
      changed, no action is done.  There are the following possible
d464 4
a467 2
          would create a foreign key constraint violation.  This is
          the default action.
d476 4
a479 3
          Same as <literal>NO ACTION</literal> except that this action
          will not be deferred even if the rest of the constraint is
          deferrable and deferred.
d499 1
a499 1
          Set the referencing column values to null.
d508 1
a508 1
          Set the referencing column values to their default value.
d516 4
a519 5
      If primary key column is updated frequently, it may be wise to
      add an index to the foreign key column so that <literal>NO
      ACTION</literal> and <literal>CASCADE</literal> actions
      associated with the foreign key column can be more efficiently
      performed.
d849 3
a851 3
	id serial,
	name text,
	location text
@


1.83
log
@Tablespace examples for CREATE TABLE/INDEX/SCHEMA/DATABASE as well as
some other examples for CREATE DATABASE.

Gavin Sherry
@
text
@d2 1
a2 1
$PostgreSQL: pgsql-server/doc/src/sgml/ref/create_table.sgml,v 1.82 2004/06/18 06:13:05 tgl Exp $
d36 4
a39 1
{ NOT NULL | NULL | UNIQUE | PRIMARY KEY |
d48 2
a49 2
{ UNIQUE ( <replaceable class="PARAMETER">column_name</replaceable> [, ... ] ) |
  PRIMARY KEY ( <replaceable class="PARAMETER">column_name</replaceable> [, ... ] ) |
d610 12
d968 1
a968 1
   <title>TABLESPACE</title>
@


1.82
log
@Tablespaces.  Alternate database locations are dead, long live tablespaces.

There are various things left to do: contrib dbsize and oid2name modules
need work, and so does the documentation.  Also someone should think about
COMMENT ON TABLESPACE and maybe RENAME TABLESPACE.  Also initlocation is
dead, it just doesn't know it yet.

Gavin Sherry and Tom Lane.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql-server/doc/src/sgml/ref/create_table.sgml,v 1.81 2004/05/19 23:10:43 momjian Exp $
d824 12
@


1.81
log
@Clearify CHECK handling of unknown test values.

Karl O. Pinc
@
text
@d2 1
a2 1
$PostgreSQL: pgsql-server/doc/src/sgml/ref/create_table.sgml,v 1.80 2004/03/22 16:18:50 tgl Exp $
d31 1
d52 1
a52 1
  
d325 1
a325 1
   
d409 1
a409 1
    REFERENCES <replaceable class="parameter">reftable</replaceable> [ ( <replaceable class="parameter">refcolumn</replaceable> [, ... ] ) ] 
d411 1
a411 1
    [ ON DELETE <replaceable class="parameter">action</replaceable> ] 
d518 1
a518 1
   
d557 1
a557 1
      block can be controlled using <literal>ON COMMIT</literal>. 
d565 2
a566 2
	  No special action is taken at the ends of transactions.
	  This is the default behavior.
d568 1
a568 1
     	</listitem>
d570 1
a570 1
           
d577 1
a577 1
	  <xref linkend="sql-truncate"> is done at each commit.
d587 1
a587 1
	  transaction block.
d595 12
d608 1
a608 1
 </refsect1>    
d712 1
a712 1
  
d735 1
a735 1
 
d765 1
a765 1
); 
d828 1
a828 1
 
d843 1
a843 1
    standard, 
d905 1
a905 1
   
d939 9
d957 1
@


1.80
log
@Clean up rather poor description of the difference between INHERITS and
LIKE.  Per gripe from Patrick Samson.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql-server/doc/src/sgml/ref/create_table.sgml,v 1.79 2004/03/09 16:57:47 neilc Exp $
d386 7
a392 4
      insert or update operation to succeed.  A check constraint
      specified as a column constraint should reference that column's
      value only, while an expression appearing in a table constraint
      may reference multiple columns.
@


1.79
log
@Refer to GUC variables using <xref> tags rather than <varname> tags,
where appropriate. Add "id" and "xreflabel" tags to the descriptions
of the GUC variables to facilitate this. Also make a few minor docs
cleanups.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql-server/doc/src/sgml/ref/create_table.sgml,v 1.78 2004/03/01 17:58:39 neilc Exp $
d188 2
a189 2
      the new table automatically inherits all column names, their data types, and
      not-null constraints.
d192 5
a196 3
      Unlike <literal>INHERITS</literal>, the new table and inherited table
      are complete decoupled after creation has been completed.  Data inserted
      into the new table will not be reflected into the parent table.
d199 3
a201 3
      Default expressions for the inherited column definitions will only be included if
      <literal>INCLUDING DEFAULTS</literal> is specified.  The default is to exclude
      default expressions.
d212 13
a224 1
      columns.  If the same column name exists in more than one parent
d229 1
a229 1
      contains a column that is also inherited, the data type must
@


1.78
log
@Add a few more xrefs, where they seemed appropriate: for example, refer
to the discussion of planner statistics in the documentation for the
default_statistics_target GUC var.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql-server/doc/src/sgml/ref/create_table.sgml,v 1.77 2003/12/01 22:07:58 momjian Exp $
d252 1
a252 1
      <varname>default_with_oids</varname> configuration parameter. (If
@


1.77
log
@This patch adds a new GUC var, "default_with_oids", which follows the
proposal for eventually deprecating OIDs on user tables that I posted
earlier to pgsql-hackers. pg_dump now always specifies WITH OIDS or
WITHOUT OIDS when dumping a table. The documentation has been updated.

Neil Conway
@
text
@d2 1
a2 1
$PostgreSQL: pgsql-server/doc/src/sgml/ref/create_table.sgml,v 1.76 2003/11/29 19:51:38 pgsql Exp $
d154 4
a157 1
      The data type of the column. This may include array specifiers.
@


1.76
log
@
$Header: -> $PostgreSQL Changes ...
@
text
@d2 1
a2 1
$PostgreSQL: /cvsroot/pgsql-server/doc/src/sgml/ref/create_table.sgml,v 1.75 2003/11/14 22:56:11 tgl Exp $
d114 6
a119 6
      session, or optionally at the end of the current transaction 
      (see ON COMMIT 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.
d246 7
a252 4
      should have OIDs (object identifiers) assigned to them.  The
      default is to have OIDs.  (If the new table inherits from any
      tables that have OIDs, then <literal>WITH OIDS</> is forced even
      if the command says <literal>WITHOUT OIDS</>.)
d256 14
a269 9
      Specifying <literal>WITHOUT OIDS</> allows the user to suppress
      generation of OIDs for rows of a table.  This may be worthwhile
      for large tables, since it will reduce OID consumption and
      thereby postpone wraparound of the 32-bit OID counter.  Once the
      counter wraps around, uniqueness of OIDs can no longer be
      assumed, which considerably reduces their usefulness. Specifying
      <literal>WITHOUT OIDS</literal> also reduces the space required
      to store the table on disk by 4 bytes per row of the table,
      thereby improving performance.
d583 4
a586 1
     Whenever an application makes use of OIDs to identify specific
d593 1
a593 5
     purpose.  (It is likely that future <productname>PostgreSQL</>
     releases will use a separate OID counter for each table, so that
     it will be <emphasis>necessary</>, not optional, to include
     <structfield>tableoid</> to have a unique identifier
     database-wide.)
@


1.75
log
@Repair error in syntax documentation for CREATE TABLE: one does not put
a comma between multiple column_constraint's for a single column.
Per report from Tomislaw Kitynski.
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql-server/doc/src/sgml/ref/create_table.sgml,v 1.74 2003/11/12 04:08:07 momjian Exp $
@


1.74
log
@Here's a patch that adds some text mentioning that
RESTRICT is not deferrable to the create table reference
page.

Stephan Szabo
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql-server/doc/src/sgml/ref/create_table.sgml,v 1.73 2003/11/01 01:56:29 petere Exp $
d24 1
a24 1
    { <replaceable class="PARAMETER">column_name</replaceable> <replaceable class="PARAMETER">data_type</replaceable> [ DEFAULT <replaceable>default_expr</> ] [ <replaceable class="PARAMETER">column_constraint</replaceable> [, ... ] ]
@


1.73
log
@Spell checking, consistent terminology.
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql-server/doc/src/sgml/ref/create_table.sgml,v 1.72 2003/09/09 18:28:52 tgl Exp $
d442 3
a444 1
          Same as <literal>NO ACTION</literal>.
@


1.73.2.1
log
@Here's a patch that adds some text mentioning that
RESTRICT is not deferrable to the create table reference
page.

Stephan Szabo
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql-server/doc/src/sgml/ref/create_table.sgml,v 1.73 2003/11/01 01:56:29 petere Exp $
d442 1
a442 3
          Same as <literal>NO ACTION</literal> except that this action
          will not be deferred even if the rest of the constraint is
          deferrable and deferred.
@


1.73.2.2
log
@Repair error in syntax documentation for CREATE TABLE: one does not put
a comma between multiple column_constraint's for a single column.
Per report from Tomislaw Kitynski.
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql-server/doc/src/sgml/ref/create_table.sgml,v 1.74 2003/11/12 04:08:07 momjian Exp $
d24 1
a24 1
  { <replaceable class="PARAMETER">column_name</replaceable> <replaceable class="PARAMETER">data_type</replaceable> [ DEFAULT <replaceable>default_expr</> ] [ <replaceable class="PARAMETER">column_constraint</replaceable> [ ... ] ]
@


1.72
log
@Remove a bunch of content-free Diagnostics sections, as per previous
discussion.  (Still have some work to do editing the remainder.)
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql-server/doc/src/sgml/ref/create_table.sgml,v 1.71 2003/08/31 17:32:22 petere Exp $
d185 2
a186 2
      the new table automatically inherits all column names, their datatypes, and
      <literal>NOT NULL</literal> constraints.
@


1.71
log
@Add/edit index entries.
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql-server/doc/src/sgml/ref/create_table.sgml,v 1.70 2003/06/12 18:34:06 tgl Exp $
a565 17


 <refsect1 id="SQL-CREATETABLE-diagnostics">
  <title>Diagnostics</title>

  <variablelist>
   <varlistentry>
    <term><computeroutput>CREATE TABLE</computeroutput></term>
    <listitem>
     <para>
      Message returned if the table was successfully created.
     </para>
    </listitem>
   </varlistentry>
  </variablelist>
 </refsect1>

@


1.70
log
@Fix broken markup.
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql-server/doc/src/sgml/ref/create_table.sgml,v 1.69 2003/06/12 07:49:43 momjian Exp $
d16 4
@


1.70.2.1
log
@Update this branch to match CVS head, includes WIN32 improvements.
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql-server/doc/src/sgml/ref/create_table.sgml,v 1.71 2003/08/31 17:32:22 petere Exp $
a15 4

 <indexterm zone="sql-createtable">
  <primary>CREATE TABLE</primary>
 </indexterm>
@


1.69
log
@Brief note about sequence cache not being cleared in other backends.

Actually clear the cache in the backend making the alteration.  This
follows in the footsteps of setval().

Rod Taylor
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql-server/doc/src/sgml/ref/create_table.sgml,v 1.68 2003/05/04 00:03:55 tgl Exp $
d193 1
@


1.68
log
@When a TIMESTAMP, TIME, or INTERVAL precision is specified larger than our
implementation limits, do not issue an ERROR; instead issue a NOTICE and use
the max supported value.  Per pgsql-general discussion of 28-Apr, this is
needed to allow easy porting from pre-7.3 releases where the limits were
higher.

Unrelated change in same area: accept GLOBAL TEMP/TEMPORARY as a synonym
for TEMPORARY, as per pgsql-hackers discussion of 15-Apr.  We previously
rejected it, but that was based on a misreading of the spec --- SQL92's
GLOBAL temp tables are really closer to what we have than their LOCAL ones.
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql-server/doc/src/sgml/ref/create_table.sgml,v 1.67 2003/04/22 10:08:08 petere Exp $
d21 2
a22 1
    | <replaceable>table_constraint</replaceable> }  [, ... ]
d173 20
@


1.67
log
@More editing of reference pages.
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql-server/doc/src/sgml/ref/create_table.sgml,v 1.66 2003/04/14 18:08:58 tgl Exp $
d19 1
a19 1
CREATE [ [ LOCAL ] { TEMPORARY | TEMP } ] TABLE <replaceable class="PARAMETER">table_name</replaceable> (
d104 1
a104 1
    <term><literal>[LOCAL] TEMPORARY</> or <literal>[LOCAL] TEMP</></term>
d118 3
a120 1
      The <literal>LOCAL</literal> word is optional.  But see under
d200 1
a200 1
      <application>PostgreSQL</application> automatically allows the
d791 2
a792 1
    resembles that of SQL standard, the effect is not the same.  In the standard,
d804 1
a804 1
    The behavior of temporary tables mandated by the standard is
d814 3
@


1.66
log
@Another try at correctly explaining the difference between Postgres and
SQL92 temp tables.  Possibly I got it right this time.
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql-server/doc/src/sgml/ref/create_table.sgml,v 1.65 2003/04/14 15:40:02 tgl Exp $
d32 1
a32 1
  REFERENCES <replaceable class="PARAMETER">reftable</replaceable> [ ( <replaceable class="PARAMETER">refcolumn</replaceable> ) ] [ MATCH FULL | MATCH PARTIAL ]
d43 1
a43 1
    [ MATCH FULL | MATCH PARTIAL ] [ ON DELETE <replaceable class="parameter">action</replaceable> ] [ ON UPDATE <replaceable class="parameter">action</replaceable> ] }
d61 3
a63 4
   specified schema.  Otherwise it is created in the current schema (the one
   at the front of the search path; see <literal>CURRENT_SCHEMA()</>).
   TEMP tables exist in a special schema, so a schema name may not be
   given when creating a TEMP table.
d70 1
a70 1
   type that represents the tuple type (structure type) corresponding
d83 2
a84 3
   to succeed.  A constraint is a named rule: an SQL object which
   helps define valid sets of values by putting limits on the results
   of insert, update, or delete operations performed on a table.
d159 1
a159 1
      is any variable-free expression (subselects and cross-references
d168 1
a168 1
      for a column, then the default is NULL.
d213 2
a214 1
    <term><literal>WITH OIDS</> or <literal>WITHOUT OIDS</></term>
d252 1
a252 1
      The column is not allowed to contain NULL values.
d261 1
a261 1
      The column is allowed to contain NULL values. This is the default.
d278 1
a278 1
      The <literal>UNIQUE</literal> constraint specifies a rule that a
d286 1
a286 1
      For the purpose of a unique constraint, NULL values are not
d305 1
a305 1
      may contain only unique (non-duplicate), non-NULL values.
d309 1
a309 1
      meta-data about the design of the schema, as a primary key
d331 6
a336 7
      <literal>CHECK</> clauses specify integrity constraints or tests
      which new or updated rows must satisfy for an insert or update
      operation to succeed. Each constraint must be an expression
      producing a Boolean result.  A condition appearing within a
      column definition should reference that column's value only,
      while a condition appearing as a table constraint may reference
      multiple columns.
d341 1
a341 1
      subselects nor refer to variables other than columns of the
a343 1

d360 1
a360 1
      The <literal>REFERENCES</literal> column constraint specifies
d374 10
a383 10
      A value added to these columns is matched against the values of
      the referenced table and referenced columns using the given
      match type.  There are three match types: <literal>MATCH
      FULL</>, <literal>MATCH PARTIAL</>, and a default match type if
      none is specified. <literal>MATCH FULL</> will not allow one
      column of a multicolumn foreign key to be NULL unless all
      foreign key columns are NULL. The default match type allows some
      foreign key columns to be NULL while other parts of the foreign
      key are not NULL. <literal>MATCH PARTIAL</> is not yet
      implemented.
d390 1
a390 1
      action to do when a referenced row in the referenced table is
d434 1
a434 1
          Set the referencing column values to NULL.
d449 1
d452 4
a455 4
      add an index to the <literal>REFERENCES</literal> column so that
      <literal>NO ACTION</literal> and <literal>CASCADE</literal>
      actions associated with the <literal>REFERENCES</literal>
      column can be more efficiently performed.
a456 1

d461 2
a462 1
    <term><literal>DEFERRABLE</literal> or <literal>NOT DEFERRABLE</literal></term>
d478 2
a479 1
    <term><literal>INITIALLY IMMEDIATE</literal> or <literal>INITIALLY DEFERRED</literal></term>
d543 10
a552 39
  <msgset>
   <msgentry>
    <msg>
     <msgmain>
      <msgtext>
       <simpara><computeroutput>CREATE TABLE</computeroutput></simpara>
      </msgtext>
     </msgmain>
    </msg>

    <msgexplan>
     <para>
      Message returned if table is successfully created.
     </para>
    </msgexplan>
   </msgentry>


   <msgentry>
    <msg>
     <msgmain>
      <msgtext>
       <simpara><computeroutput>ERROR</computeroutput></simpara>
      </msgtext>
     </msgmain>
    </msg>

    <msgexplan>
     <para>
      Message returned if table creation failed.  This is usually
      accompanied by some descriptive text, such as:
      <computeroutput>ERROR: Relation '<replaceable
      class="parameter">table</replaceable>' already
      exists</computeroutput>, which occurs at run time if the table
      specified already exists in the database.
     </para>
    </msgexplan>
   </msgentry>
  </msgset>
a596 11
     The SQL92 standard says that <literal>CHECK</> column constraints
     may only refer to the column they apply to; only
     <literal>CHECK</> table constraints may refer to multiple
     columns.  <productname>PostgreSQL</productname> does not enforce
     this restriction; it treats column and table check constraints
     alike.
    </para>
   </listitem>

   <listitem>
    <para>
d615 6
a620 6
    code        CHARACTER(5) CONSTRAINT firstkey PRIMARY KEY,
    title       CHARACTER VARYING(40) NOT NULL,
    did         DECIMAL(3) NOT NULL,
    date_prod   DATE,
    kind        CHAR(10),
    len         INTERVAL HOUR TO MINUTE
d626 2
a627 2
     did    DECIMAL(3) PRIMARY KEY DEFAULT NEXTVAL('serial'),
     name   VARCHAR(40) NOT NULL CHECK (name &lt;&gt; '')
d637 1
a637 1
    vector  INT[][]
d643 3
a645 2
   Define a unique table constraint for the table films.  Unique table
   constraints can be defined on one or more columns of the table:
d649 6
a654 6
    code        CHAR(5),
    title       VARCHAR(40),
    did         DECIMAL(3),
    date_prod   DATE,
    kind        VARCHAR(10),
    len         INTERVAL HOUR TO MINUTE,
d665 2
a666 2
    did     DECIMAL(3) CHECK (did > 100),
    name    VARCHAR(40)
d676 2
a677 2
    did     DECIMAL(3),
    name    VARCHAR(40)
d690 6
a695 6
    code        CHAR(5),
    title       VARCHAR(40),
    did         DECIMAL(3),
    date_prod   DATE,
    kind        VARCHAR(10),
    len         INTERVAL HOUR TO MINUTE,
d709 2
a710 2
    did     DECIMAL(3),
    name    CHAR VARYING(40),
d717 2
a718 2
    did     DECIMAL(3) PRIMARY KEY,
    name    VARCHAR(40)
d725 4
a728 4
   <literal>name</literal>, and arranges for the default value of
   column <literal>did</literal> to be generated by selecting the next
   value of a sequence object.  The default value of
   <literal>modtime</literal> will be the time at which the row is
d733 3
a735 3
    name      VARCHAR(40) DEFAULT 'luso films',
    did       INTEGER DEFAULT NEXTVAL('distributors_serial'),
    modtime   TIMESTAMP DEFAULT CURRENT_TIMESTAMP
d747 2
a748 2
    did     DECIMAL(3) CONSTRAINT no_null NOT NULL,
    name    VARCHAR(40) NOT NULL
d758 2
a759 2
    did     DECIMAL(3),
    name    VARCHAR(40) UNIQUE
d767 2
a768 2
    did     DECIMAL(3),
    name    VARCHAR(40),
d781 1
a781 2
   and to a subset of SQL99, with exceptions listed below and in the
   descriptions above.
d789 1
a789 1
    resembles that of SQL92, the effect is not the same.  In the standard,
d796 1
a796 1
    purposes, whereas the spec's approach constrains all instances of a
d800 5
a804 7
   <note>
    <para>
     The spec-mandated behavior of temporary tables is widely ignored.
     <productname>PostgreSQL</productname>'s behavior on this point is similar
     to that of several other RDBMSs.
    </para>
   </note>
d807 1
a807 1
    SQL92's distinction between global and local temporary tables
d815 2
a816 2
    also resembles SQL92, but has some differences.
    If the <literal>ON COMMIT</> clause is omitted, SQL92 specifies that the
d820 13
a832 1
    DROP</literal> option does not exist in SQL92.
d842 2
a843 2
    extension to SQL92 that is included for compatibility with some
    other RDBMSs (and for symmetry with the <literal>NOT
a847 36
   
  <refsect2>
   <title>Assertions</title>

   <para>
    An assertion is a special type of integrity constraint and shares
    the same namespace as other constraints. However, an assertion is
    not necessarily dependent on one particular table as constraints
    are, so SQL92 provides the <command>CREATE ASSERTION</command>
    statement as an alternate method for defining a constraint:

<synopsis>
CREATE ASSERTION <replaceable>name</replaceable> CHECK ( <replaceable>condition</replaceable> )
</synopsis>
   </para>

   <para>
    <productname>PostgreSQL</> does not implement assertions at present.
   </para>
  </refsect2>

<!--    
    <para>
     Domain constraints are defined by <command>CREATE
     DOMAIN</command> or <command>ALTER DOMAIN</command> statements:
    </para>
    <para>
     Domain constraint: 

     <synopsis>
[ CONSTRAINT <replaceable>constraint_name</replaceable> ] CHECK <replaceable>constraint</replaceable> 
    [ {INITIALLY DEFERRED | INITIALLY IMMEDIATE} ]
    [ [ NOT ] DEFERRABLE ]
     </synopsis>
    </para>
-->
@


1.65
log
@Minor copy-editing.
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql-server/doc/src/sgml/ref/create_table.sgml,v 1.64 2003/04/14 15:24:46 tgl Exp $
d831 3
a833 4
    temporary tables are associated with modules; a temporary table is created
    just once and automatically exists (starting with empty contents) in every
    session that uses the module.
    <productname>PostgreSQL</productname> does not have modules, and
d835 4
a838 3
    TABLE</literal> command for each temporary table to be used.
    The notion of <literal>GLOBAL</literal> temporary tables found in SQL92
    is not in <productname>PostgreSQL</productname> at all.
d850 7
d863 1
a863 1
    DROP</literal> option does not exist in SQL92 at all.
@


1.64
log
@Clarify description of our deviation from standard for temp tables,
per suggestion from Mike Sykes.
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql-server/doc/src/sgml/ref/create_table.sgml,v 1.63 2003/03/25 16:15:39 petere Exp $
d820 1
a820 1
   The <command>CREATE TABLE</command> conforms to SQL92 Intermediate
d837 2
d850 1
a850 1
    The optional <literal>ON COMMIT</literal> clause for temporary tables
@


1.63
log
@Merge documentation into one book.  (Build with "make html".)  Replace
vague cross-references with real links.
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql-server/doc/src/sgml/ref/create_table.sgml,v 1.62 2003/02/19 03:13:25 momjian Exp $
d829 8
a836 3
    In addition to the local temporary table, SQL92 also defines a
    <literal>CREATE GLOBAL TEMPORARY TABLE</literal> statement.
    Global temporary tables are also visible to other sessions.
d839 8
d848 7
a854 12
    For temporary tables, there is an optional <literal>ON COMMIT</literal> clause:
<synopsis>
CREATE { GLOBAL | LOCAL } TEMPORARY TABLE <replaceable class="parameter">table</replaceable> ( <replaceable class="parameter">...</replaceable> ) [ ON COMMIT { DELETE | PRESERVE } ROWS ] 
</synopsis>

    The <literal>ON COMMIT</literal> clause specifies whether or not
    the temporary table should be emptied of rows whenever
    <command>COMMIT</command> is executed. If the <literal>ON
    COMMIT</> clause is omitted, SQL92 specifies that the default is
    <literal>ON COMMIT DELETE ROWS</>.  However, the behavior of
    <productname>PostgreSQL</productname> is always like <literal>ON
    COMMIT PRESERVE ROWS</literal>.
d865 1
a865 1
    other RDBMS (and for symmetry with the <literal>NOT
@


1.62
log
@This patch includes more SGML markup fixes as well as a few minor
additions to the docs.

Neil Conway
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql-server/doc/src/sgml/ref/create_table.sgml,v 1.61 2003/01/19 00:13:29 momjian Exp $
a149 2
      Refer to the &cite-user; for further information about data
      types and arrays.
@


1.61
log
@This patch includes a lot of minor cleanups to the SGML documentation,
including:

- replacing all the appropriate usages of <citetitle>PostgreSQL
...</citetitle> with &cite-user;, &cite-admin;, and so on

- fix an omission in the EXECUTE documentation

- add some more text to the EXPLAIN documentation

- improve the PL/PgSQL RETURN NEXT documentation (more work to do here)

- minor markup fixes


Neil Conway
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql-server/doc/src/sgml/ref/create_table.sgml,v 1.60 2002/12/16 19:08:25 tgl Exp $
d233 4
a236 1
      assumed, which considerably reduces their usefulness.
d887 2
a888 2
     Domain constraints are defined by CREATE DOMAIN or ALTER DOMAIN
     statements:
@


1.60
log
@Document that zero-column tables are allowed (and non-standard).
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql-server/doc/src/sgml/ref/create_table.sgml,v 1.59 2002/11/21 23:34:43 petere Exp $
d150 2
a151 2
      Refer to the <citetitle>User's Guide</citetitle> for further
      information about data types and arrays.
@


1.59
log
@Fixups for man pages
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql-server/doc/src/sgml/ref/create_table.sgml,v 1.58 2002/11/11 22:19:20 tgl Exp $
d916 13
@


1.58
log
@Code review for ON COMMIT patch.  Make the actual on-commit action happen
before commit, not after :-( --- the original coding is not only unsafe
if an error occurs while it's processing, but it generates an invalid
sequence of WAL entries.  Resurrect 7.2 logic for deleting items when
no longer needed.  Use an enum instead of random macros.  Editorialize
on names used for routines and constants.  Teach backend/nodes routines
about new field in CreateTable struct.  Add a regression test.
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql-server/doc/src/sgml/ref/create_table.sgml,v 1.57 2002/11/09 23:56:38 momjian Exp $
d925 2
a926 2
   <member><xref linkend="sql-altertable"></member>
   <member><xref linkend="sql-droptable"></member>
@


1.57
log
@Add code to handle [ON COMMIT { PRESERVE ROWS | DELETE ROWS | DROP }]
for temp tables.

Gavin Sherry
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql-server/doc/src/sgml/ref/create_table.sgml,v 1.56 2002/09/02 06:20:53 momjian Exp $
d24 2
a25 1
[ WITH OIDS | WITHOUT OIDS ] [ON COMMIT { PRESERVE ROWS | DELETE ROWS | DROP } ]
d111 2
a112 2
      session or optionally at the end of the current transaction 
      (See ON COMMIT below).  Existing permanent tables with the same 
d497 1
a497 1
      The behaviour of temporary tables at the end of a transaction
d499 1
a499 6
      The table will exhibit the same behavior at the end of
      transaction blocks for the duration of the session unless
      ON COMMIT DROP is specified or the temporary table is dropped.
     </para>
     <para>
      The three parameters to ON COMMIT are:
d506 2
a507 2
          The rows in the temporary table will persist after the
          transaction block.
d516 3
a518 2
          All rows in the temporary table will be deleted at the 
          end of the transaction block.
d527 2
a528 1
          The temporary table will be dropped at the end of the transaction.
@


1.56
log
@This patch fixes a minor inaccuracy in the documentation: NOT NULL is
not synonymous with CHECK (xxx IS NOT NULL) -- for example, consider
ALTER TABLE ADD PRIMARY KEY, which checks for 'NOT NULL', not a check
constraint.

Neil Conway
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql-server/doc/src/sgml/ref/create_table.sgml,v 1.55 2002/05/18 15:44:47 petere Exp $
d24 1
a24 1
[ WITH OIDS | WITHOUT OIDS ]
d110 5
a114 4
      session.  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
a490 1
  </variablelist>
d492 33
d526 13
@


1.56.2.1
log
@Fixups for man pages
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql-server/doc/src/sgml/ref/create_table.sgml,v 1.56 2002/09/02 06:20:53 momjian Exp $
d881 2
a882 2
   <member><xref linkend="sql-altertable" endterm="sql-altertable-title"></member>
   <member><xref linkend="sql-droptable" endterm="sql-droptable-title"></member>
@


1.55
log
@Revise command completion tags as per hackers message on 20 March.
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v 1.54 2002/04/23 02:07:16 tgl Exp $
d250 1
a250 3
      The column is not allowed to contain NULL values.  This is
      equivalent to the column constraint <literal>CHECK (<replaceable
      class="PARAMETER">column</replaceable> NOT NULL)</literal>.
@


1.54
log
@Update SQL-command reference pages for schema features.
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v 1.53 2002/03/22 19:20:40 petere Exp $
d506 1
a506 1
       <simpara><computeroutput>CREATE</computeroutput></simpara>
@


1.53
log
@Spell checking and markup additions
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v 1.52 2002/01/20 22:19:56 petere Exp $
d58 11
d72 1
a72 1
   name as any existing data type.
d77 1
a77 2
   effective limit is lower because of tuple-length constraints).  A
   table cannot have the same name as a system catalog table.
d110 3
a112 2
      session.  Existing persistent tables with the same name are not
      visible to the current session while the temporary table exists.
d129 1
a129 1
      The name of the table to be created.
@


1.52
log
@Spell-check and markup police
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v 1.51 2002/01/03 06:26:22 momjian Exp $
d523 1
a523 1
      exists</computeroutput>, which occurs at runtime if the table
@


1.51
log
@Add mention of index on foreign key for frequently updated primary key
tables.
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v 1.50 2001/12/08 03:24:35 thomas Exp $
d370 1
a370 1
      column of a multi-column foreign key to be NULL unless all
d586 1
a586 1
     inheritance and unique constraints rather disfunctional.
d803 1
a803 1
    other RDBMSes (and for symmetry with the <literal>NOT
@


1.50
log
@Use PostgreSQL consistantly throughout docs. Before, usage was split evenly
 between Postgres and PostgreSQL.
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v 1.49 2001/11/18 20:35:02 petere Exp $
d440 7
d482 2
@


1.49
log
@Initial round of tweakage for man pages
@
text
@d2 2
a3 2
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v 1.48 2001/10/22 18:14:47 petere Exp $
Postgres documentation
d189 2
a190 1
      Postgres automatically allows the created table to inherit
@


1.48
log
@Make the CREATE TABLE ref page more readable and update some information.
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v 1.47 2001/10/09 18:46:00 petere Exp $
d8 1
a8 1
  <refentrytitle>CREATE TABLE</refentrytitle>
d451 1
a451 1
      (using the <xref linkend="sql-set-constraints"> command).
d469 1
a469 1
      altered with the <xref linkend="sql-set-constraints"> command.
d557 1
a557 1
     linkend="sql-createindex"> for more information.)
@


1.47
log
@Bunch of copy fitting and style sheet tweakage to get decent looking print
output (from pdfjadetex).  Also updated instructions to install documentation
processing toolchain.
@
text
@d2 1
a2 1
$Header: /home/projects/pgsql/cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v 1.46 2001/09/13 15:55:24 petere Exp $
d8 1
a8 3
  <refentrytitle id="sql-createtable-title">
   CREATE TABLE
  </refentrytitle>
d11 1
d13 2
a14 6
  <refname>
   CREATE TABLE
  </refname>
  <refpurpose>
   define a new table
  </refpurpose>
d16 1
d18 9
a26 9
  <refsynopsisdivinfo>
   <date>2001-01-11</date>
  </refsynopsisdivinfo>
  <synopsis>
CREATE [ TEMPORARY | TEMP ] TABLE <replaceable class="PARAMETER">table_name</replaceable> (
    { <replaceable class="PARAMETER">column_name</replaceable> <replaceable class="PARAMETER">type</replaceable> [ <replaceable class="PARAMETER">column_constraint</replaceable> [ ... ] ]
      | <replaceable>table_constraint</replaceable> }  [, ... ] )
    [ INHERITS ( <replaceable>parent_table</replaceable> [, ... ] ) ]
    [ WITH OIDS | WITHOUT OIDS ]
a27 1
where <replaceable class="PARAMETER">column_constraint</replaceable> can be:
d29 7
a35 5
{ NOT NULL | NULL | UNIQUE | PRIMARY KEY | DEFAULT <replaceable class="PARAMETER">value</replaceable> | CHECK (<replaceable class="PARAMETER">condition</replaceable>) |
  REFERENCES <replaceable class="PARAMETER">table</replaceable> [ ( <replaceable class="PARAMETER">column</replaceable> ) ] [ MATCH FULL | MATCH PARTIAL ]
   [ ON DELETE <replaceable class="parameter">action</replaceable> ] [ ON UPDATE <replaceable class="parameter">action</replaceable> ]
   [ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ]
}
a36 1
and <replaceable class="PARAMETER">table_constraint</replaceable> can be:
d40 5
a44 6
  CHECK ( <replaceable class="PARAMETER">condition</replaceable> ) |
  FOREIGN KEY ( <replaceable class="PARAMETER">column_name</replaceable> [, ... ] ) REFERENCES <replaceable class="PARAMETER">table</replaceable> [ ( <replaceable class="PARAMETER">column</replaceable> [, ... ] ) ]
   [ MATCH FULL | MATCH PARTIAL ] [ ON DELETE <replaceable class="parameter">action</replaceable> ] [ ON UPDATE <replaceable class="parameter">action</replaceable> ]
   [ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ]
}
  </synopsis>
a45 179
  <refsect2 id="R2-SQL-CREATETABLE-1">
   <title>
    Inputs
   </title>

   <para>

    <variablelist>
     <varlistentry>
      <term>TEMPORARY or TEMP</term>
      <listitem>
       <para>
	If specified, the table is created only for this session, and is
	automatically dropped on session exit.
	Existing permanent tables with the same name are not visible
	(in this session) while the temporary table exists.
	Any indexes created on a temporary table are automatically
	temporary as well.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><replaceable class="PARAMETER">table_name</replaceable></term>
      <listitem>
       <para>
	The name of the new table to be created.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><replaceable class="PARAMETER">column_name</replaceable></term>
      <listitem>
       <para>
	The name of a column to be created in the new table.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><replaceable class="PARAMETER">type</replaceable></term>
      <listitem>
       <para>
	The type of the column. This may include array specifiers.
	Refer to the <citetitle>PostgreSQL User's Guide</citetitle> for
	further information about data types and arrays.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><replaceable class="PARAMETER">parent_table</replaceable></term>
      <listitem>
       <para>
	The optional INHERITS clause specifies a list of table
	names from which this table automatically inherits all fields.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term>WITH OIDS or WITHOUT OIDS</term>
      <listitem>
       <para>
        This optional clause specifies whether rows of the new table should
	have OIDs (object identifiers) assigned to them.  The default is
	WITH OIDS.  (If the new table inherits from any tables that have OIDs,
	then WITH OIDS is forced even if the command says WITHOUT OIDS.)
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><replaceable class="PARAMETER">constraint_name</replaceable></term>
      <listitem>
       <para>
        An optional name for a column or table constraint.  If not specified,
	the system generates a name.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><replaceable class="PARAMETER">value</replaceable></term>
      <listitem>
       <para>
	A default value for a column.
	See the DEFAULT clause for more information.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><replaceable class="PARAMETER">condition</replaceable></term>
      <listitem>
       <para>
	CHECK clauses specify integrity constraints or tests which new or
	updated rows must satisfy for an insert or update operation to
	succeed. Each constraint must be an expression producing
	a boolean result.
	A condition appearing within a column definition should reference
	that column's value only, while a condition appearing as a table
	constraint may reference multiple columns.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><replaceable class="PARAMETER">table</replaceable></term>
      <listitem>
       <para>
        The name of an existing table to be referenced by a foreign
	key constraint.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><replaceable class="PARAMETER">column</replaceable></term>
      <listitem>
       <para>
        The name of a column in an existing table to be referenced by a
	foreign key constraint.  If not specified, the primary key of
	the existing table is assumed.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><replaceable class="PARAMETER">action</replaceable></term>
      <listitem>
       <para>
        A keyword indicating the action to take when a foreign key
	constraint is violated.
       </para>
      </listitem>
     </varlistentry>
    </variablelist>
   </para>    
  </refsect2>

  <refsect2 id="R2-SQL-CREATETABLE-2">
   <title>
    Outputs
   </title>
   <para>

    <variablelist>
     <varlistentry>
      <term><computeroutput>
CREATE
       </computeroutput></term>
      <listitem>
       <para>
	Message returned if table is successfully created.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><computeroutput>
ERROR
       </computeroutput></term>
      <listitem>
       <para>
	Message returned if table creation failed.
	This is usually accompanied by some descriptive text, such as:
	<computeroutput>
ERROR:  Relation '<replaceable class="parameter">table</replaceable>' already exists
	</computeroutput>
	, which occurs at runtime if the table specified already exists
	in the database.
       </para>
      </listitem>
     </varlistentry>
    </variablelist>
   </para>
  </refsect2>
d48 2
a49 4
 <refsect1 id="R1-SQL-CREATETABLE-1">
  <title>
   Description
  </title>
d52 2
a53 2
   <command>CREATE TABLE</command> will enter a new, initially empty table
   into the current database. The table will be owned by the user issuing the
d58 4
a61 5
   Each <replaceable class="PARAMETER">type</replaceable>
   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
   <xref linkend="R1-SQL-DEFAULTCLAUSE-1" endterm="R1-SQL-DEFAULTCLAUSE-1-TITLE">.
d65 3
a67 7
   <note>
    <para>
     Consistent array dimensions within an
     attribute are not enforced. This will likely change in a future
     release.
    </para>
   </note>
d71 5
a75 4
   <command>CREATE TABLE</command> also automatically creates a data type
   that represents the tuple type (structure type) corresponding to one
   row of the table.  Therefore, tables can't have the same name as any
   existing datatype.
d79 7
a85 3
   A table can have no more than 1600 columns (in practice, the
   effective limit is lower because of tuple-length constraints).
   A table cannot have the same name as a system catalog table.
d89 2
a90 9
 <refsect1 id="R1-SQL-INHERITSCLAUSE-1">
  <title id="R1-SQL-INHERITSCLAUSE-1-TITLE">
   INHERITS Clause
  </title>
  <para>
   <synopsis>
INHERITS ( <replaceable class="PARAMETER">parent_table</replaceable> [, ... ] )
   </synopsis>
  </para>
d92 1
a92 11
  <para>
   The optional INHERITS
   clause specifies a list of table names from which the new table
   automatically inherits all fields.  If the same field name appears in
   more than one parent table, Postgres reports an error unless the field
   definitions match in each of the parent tables.  If there is no
   definition conflict, then the duplicate fields are merged to form a single
   field of the new table.  If the new table's own field list contains a
   field name that is also inherited, this declaration must likewise match
   the inherited field(s), and the field definitions are merged into one.
  </para>
d94 11
a104 10
  <para>
   Inherited and new field declarations of the same name must specify exactly
   the same data type to avoid an error.  They need not specify identical
   constraints --- all constraints provided from any declaration are merged
   together and all are applied to the new table.  If the new table explicitly
   specifies a default value for the field, this default overrides any
   defaults from inherited declarations of the field.  Otherwise, any parents
   that specify default values for the field must all specify the same
   default, or an error will be reported.
  </para>
d106 7
a112 10
  <para>
   Postgres automatically allows the created table to inherit functions on
   tables above it in the inheritance hierarchy; that is, if we create table
   <literal>foo</literal> inheriting from <literal>bar</literal>, then
   functions that accept the tuple type <literal>bar</literal> can also be
   applied to instances of <literal>foo</literal>.  (Currently, this works
   reliably for functions on the first or only parent table, but not so well
   for functions on additional parents.)
  </para>
 </refsect1>
d114 8
a121 9
 <refsect1 id="R1-SQL-OIDSCLAUSE-1">
  <title id="R1-SQL-OIDSCLAUSE-1-TITLE">
   OIDS Clause
  </title>
  <para>
   <synopsis>
    WITH OIDS | WITHOUT OIDS
   </synopsis>
  </para>
d123 8
a130 10
  <para>
   This clause controls whether an OID (object ID) is generated and assigned
   to each row inserted into the table.  The default is WITH OIDS.
   Specifying WITHOUT OIDS allows the user to suppress generation of
   OIDs for rows of a table.  This may be worthwhile for large
   tables, since it will reduce OID consumption and thereby postpone
   wraparound of the 32-bit OID counter.  Once the counter wraps around,
   uniqueness of OIDs can no longer be assumed, which considerably reduces
   their usefulness.
  </para>
d132 10
a141 12
  <para>
   Whenever an application makes use of OIDs to identify specific rows of
   a table, it is recommended that you create a unique index on OID for
   that table, to ensure that OIDs in the table will indeed uniquely
   identify rows even after counter wraparound.  (An index on OID is needed
   anyway for fast lookup of rows by OID.)  Avoid assuming that OIDs are
   unique across tables --- if you need a database-wide unique identifier,
   use the combination of tableoid and row OID for the purpose.  (It is
   likely that future Postgres releases will use a separate OID counter
   for each table, so that it will be <emphasis>necessary</> not optional
   to include tableoid to have a unique identifier database-wide.)
  </para>
d143 12
a154 8
  <tip>
   <para>
    WITHOUT OIDS 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.
   </para>
  </tip>
 </refsect1>
d156 7
a162 9
 <refsect1 id="R1-SQL-DEFAULTCLAUSE-1">
  <title id="R1-SQL-DEFAULTCLAUSE-1-TITLE">
   DEFAULT Clause
  </title>
  <para>
   <synopsis>
DEFAULT <replaceable class="PARAMETER">value</replaceable>
   </synopsis>
  </para>
d164 37
a200 8
  <para>
   The DEFAULT clause assigns a default data value for the column whose
   column definition it appears within.  The value is any variable-free
   expression (note that sub-selects and cross-references to other
   columns in the current table are not supported).
   The data type of a default value must match the column definition's
   data type.
  </para>
d202 10
a211 5
  <para>
   The DEFAULT expression will be used in any INSERT operation that does
   not specify a value for the column.  If there is no DEFAULT clause,
   then the default is NULL.
  </para>
d213 10
a222 4
  <refsect2 id="R2-SQL-DEFAULTCLAUSE-2">
   <title>
    Usage
   </title>
d224 9
a232 14
   <para>
    <programlisting>
CREATE TABLE distributors (
    name     VARCHAR(40) DEFAULT 'luso films',
    did      INTEGER  DEFAULT NEXTVAL('distributors_serial'),
    modtime  TIMESTAMP DEFAULT now()
);
    </programlisting>
    The above assigns a literal constant default value for the column
    <literal>name</literal>, and arranges for the default value of column
    <literal>did</literal> to be generated by selecting the next value of a
    sequence object.  The default value of <literal>modtime</literal> will
    be the time at which the row is inserted.
   </para>
d234 10
a243 13
   <para>
    It is worth remarking that
    <programlisting>
    modtime  TIMESTAMP DEFAULT 'now'
    </programlisting>
    would produce a result that is probably not the intended one: the
    string <literal>'now'</literal> will be coerced to a timestamp value
    immediately, and so the default value of <literal>modtime</literal> will
    always be the time of table creation.  This difficulty is avoided by
    specifying the default value as a function call.
   </para>
  </refsect2>
 </refsect1>
d245 6
a250 17
 <refsect1 id="R1-SQL-COLUMNCONSTRAINT-1">
  <title id="R1-SQL-COLUMNCONSTRAINT-1-TITLE">
   Column Constraints
  </title>
  <para>
   <synopsis>
[ CONSTRAINT <replaceable class="parameter">constraint_name</replaceable> ] {
    NULL | NOT NULL | UNIQUE | PRIMARY KEY | CHECK <replaceable
     class="parameter">condition</replaceable> |
    REFERENCES <replaceable class="parameter">reftable</replaceable> [ ( <replaceable class="parameter">refcolumn</replaceable> ) ]
     [ MATCH <replaceable class="parameter">matchtype</replaceable> ]
     [ ON DELETE <replaceable class="parameter">action</replaceable> ] 
     [ ON UPDATE <replaceable class="parameter">action</replaceable> ]
     [ [ NOT ] DEFERRABLE ] 
     [ INITIALLY <replaceable class="parameter">checktime</replaceable> ] }
   </synopsis>
  </para>
d252 7
a258 108
  <refsect2 id="R2-SQL-COLUMNCONSTRAINT-1">
   <title>
    Inputs
   </title>
   <para>

    <variablelist>
     <varlistentry>
      <term><replaceable class="parameter">constraint_name</replaceable></term>
      <listitem>
       <para>
	An arbitrary name given to a constraint clause.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term>NULL</term>
      <listitem>
       <para>
	The column is allowed to contain NULL values. This is the default.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term>NOT NULL</term>
      <listitem>
       <para>
	The column is not allowed to contain NULL values.
	This is equivalent to the column constraint
	CHECK (<replaceable class="PARAMETER">column</replaceable> NOT NULL).
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term>UNIQUE</term>
      <listitem>
       <para>
	The column must have unique values. In <productname>Postgres</productname>
	this is enforced by automatic creation of a unique index on the column.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term>PRIMARY KEY</term>
      <listitem>
       <para>
	This column is a primary key, which implies that other tables may rely
	on this column as a unique identifier for rows.  Both UNIQUE and
	NOT NULL are implied by PRIMARY KEY.  See PRIMARY KEY for more
	information.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term>
<replaceable class="parameter">condition</replaceable>
      </term>
      <listitem>
       <para>
	An arbitrary boolean-valued constraint condition.
       </para>
      </listitem>
     </varlistentry>
    </variablelist>
   </para>
  </refsect2>

  <refsect2 id="R2-SQL-COLUMNCONSTRAINT-2">
   <title>
    Description
   </title>

   <para>
    The optional constraint clauses specify constraints or tests which
    new or updated rows must satisfy for an insert or update
    operation to succeed.
   </para>

   <para>
    A constraint is a named rule: an SQL object which helps define
    valid sets of values by putting limits on the results of INSERT,
    UPDATE or DELETE operations performed on a table. 
   </para>

   <para>
    There are two ways to define integrity constraints:
    table constraints, covered later, and column constraints, covered here.
   </para>

   <para>
    A column constraint is an integrity constraint defined as part of a
    column definition, and logically becomes a table constraint as soon
    as it is created. The column constraints available are:

    <simplelist columns="1">
     <member>PRIMARY KEY</member>
     <member>REFERENCES</member>
     <member>UNIQUE</member>
     <member>CHECK</member>
     <member>NOT NULL</member>
    </simplelist>
   </para>
  </refsect2>
d260 3
a262 13
  <refsect2 id="R2-SQL-NOTNULL-1">
   <title>
    NOT NULL Constraint
   </title>
   <synopsis>
[ CONSTRAINT <replaceable class="parameter">name</replaceable> ] NOT NULL 
   </synopsis>
   <para>
    The NOT NULL constraint specifies a rule that a column may
    contain only non-null values. 
    This is a column constraint only, and not allowed
    as a table constraint.
   </para>
d264 8
a271 29
   <refsect3 id="R3-SQL-NOTNULL-1">
    <title>
     Outputs
    </title>
    <para>
     <variablelist>
      <varlistentry>
       <term><replaceable>status</replaceable></term>
       <listitem>
	<para>
	 <variablelist>
	  <varlistentry>
	   <term><computeroutput>
ERROR:  ExecAppend: Fail to add null value in not null attribute "<replaceable class="parameter">column</replaceable>".
	    </computeroutput></term>
	   <listitem>
	    <para>
	     This error occurs at runtime if one tries to insert a null value
	     into a column which has a NOT NULL constraint.
	    </para>
	   </listitem>
	  </varlistentry>
	 </variablelist>
	</para>
       </listitem>
      </varlistentry>
     </variablelist> 
    </para>
   </refsect3>
d273 4
a276 7
   <refsect3 id="R3-SQL-NOTNULL-2">
    <title>
     Description
    </title>
    <para>
    </para>
   </refsect3>
d278 8
a285 4
   <refsect3 id="R3-SQL-NOTNULL-3">
    <title>
     Usage
    </title>
d287 14
a300 4
    <para>
     Define two NOT NULL column constraints on the table
     <classname>distributors</classname>,
     one of which is explicitly given a name:
d302 4
a305 9
     <programlisting>
CREATE TABLE distributors (
    did      DECIMAL(3) CONSTRAINT no_null NOT NULL,
    name     VARCHAR(40) NOT NULL
);
     </programlisting>
    </para>
   </refsect3>
  </refsect2>
d307 7
a313 7
  <refsect2 id="R2-SQL-UNIQUECLAUSE-1">
   <title>
    UNIQUE Constraint
   </title>
   <synopsis>
[ CONSTRAINT <replaceable class="parameter">constraint_name</replaceable> ] UNIQUE
   </synopsis>
d315 12
a326 49
   <refsect3>
    <title>Inputs</title>
    <para>

     <variablelist>
      <varlistentry>
       <term><replaceable class="parameter">constraint_name</replaceable></term>
       <listitem>
	<para>
	 An arbitrary name given to a constraint clause.
	</para>
       </listitem>
      </varlistentry>
     </variablelist>
    </para>
   </refsect3>
   
   <refsect3>
    <title>Outputs</title>
    <para>
     <variablelist>
      <varlistentry>
       <term><replaceable>status</replaceable></term>
       <listitem>
	<para>
	 <variablelist>
	  <varlistentry>
	   <term><computeroutput>
ERROR: Cannot insert a duplicate key into a unique index.
	    </computeroutput></term>
	   <listitem>
	    <para>
	     This error occurs at runtime if one tries to insert a
	     duplicate value into a column.
	    </para>
	   </listitem>
	  </varlistentry>
	 </variablelist>
	</para>
       </listitem>
      </varlistentry>
     </variablelist>
    </para>
   </refsect3>

   <refsect3>
    <title>
     Description
    </title>
a327 19
    <para>
     The UNIQUE constraint specifies a rule that a group of one or
     more distinct columns of a table may contain only unique values.
    </para>
    <para>
     The column definitions of the specified columns do not have to
     include a NOT NULL constraint to be included in a UNIQUE
     constraint. Having more than one null value in a column without a
     NOT NULL constraint, does not violate a UNIQUE constraint. (This
     deviates from the <acronym>SQL92</acronym> definition, but is a
     more sensible convention. See the section on compatibility for more
     details.)
    </para>
    <para>
     Each UNIQUE column constraint must name a column that is
     different from the set of columns named by any other UNIQUE or
     PRIMARY KEY constraint defined for the table.
    </para>
    <note>
d329 4
a332 11
      <productname>Postgres</productname> automatically creates a unique
      index for each UNIQUE constraint, to assure
      data integrity. See CREATE INDEX for more information.
     </para>
    </note>
   </refsect3>

   <refsect3 id="R3-SQL-UNIQUECLAUSE-3">
    <title>
     Usage
    </title>
d334 2
a335 8
    <para>
     Defines a UNIQUE constraint for the <literal>name</literal> column:
     <programlisting>
CREATE TABLE distributors (
    did      DECIMAL(3),
    name     VARCHAR(40) UNIQUE
);
  </programlisting>
a336 11
     which is equivalent to the following specified as a table constraint:
     <programlisting>
CREATE TABLE distributors (
    did      DECIMAL(3),
    name     VARCHAR(40),
    UNIQUE(name)
);
     </programlisting>
    </para>
   </refsect3>
  </refsect2>
d338 2
a339 10
  <refsect2 id="R2-SQL-CHECK-1">
   <title>
    The CHECK Constraint
   </title>
   <synopsis>
[ CONSTRAINT <replaceable class="parameter">constraint_name</replaceable> ] CHECK ( <replaceable>condition</replaceable> )
   </synopsis>
   <refsect3 id="R3-SQL-CHECK-1">
    <title>Inputs</title>
    <para>
d341 6
a346 20
     <variablelist>
      <varlistentry>
       <term><replaceable class="parameter">constraint_name</replaceable></term>
       <listitem>
	<para>
	 An arbitrary name given to a constraint clause.
	</para>
       </listitem>
      </varlistentry>
      <varlistentry>
       <term><replaceable>condition</replaceable></term>
       <listitem>
	<para>
	 Any valid conditional expression evaluating to a boolean result.
	</para>
       </listitem>
      </varlistentry>
     </variablelist>
    </para>
   </refsect3>
d348 14
a361 5
   <refsect3 id="R3-SQL-CHECK-2">
    <title>
     Outputs
    </title>
    <para>
d363 12
a374 25
     <variablelist>
      <varlistentry>
       <term><replaceable>status</replaceable></term>
       <listitem>
	<para>

	 <variablelist>
	  <varlistentry>
	   <term><computeroutput>
ERROR:  ExecAppend: rejected due to CHECK constraint "<replaceable class="parameter">constraint_name</replaceable>".
	    </computeroutput></term>
	   <listitem>
	    <para>
	     This error occurs at runtime if one tries to insert an illegal
	     value into a column subject to a CHECK constraint.
	    </para>
	   </listitem>
	  </varlistentry>
	 </variablelist>
	</para>
       </listitem>
      </varlistentry>
     </variablelist>
    </para>
   </refsect3>
d376 23
a398 33
   <refsect3>
    <title>Description</title>
    <para>
     The CHECK constraint specifies a generic restriction on allowed values
     within a column. The CHECK constraint is also allowed as a table
     constraint.
    </para>
    <para>
     CHECK specifies a general boolean expression involving one or more
     columns of a table.  A new row will be rejected if the boolean
     expression evaluates to FALSE when applied to the row's values.
    </para>
    <para>
     Currently, CHECK expressions cannot contain sub-selects nor refer
     to variables other than fields of the current row.
    </para>
    <para>
     The SQL92 standard says that CHECK column constraints may only refer
     to the column they apply to; only CHECK table constraints may refer
     to multiple columns.
     <productname>Postgres</productname> does not enforce this restriction.
     It treats column and table CHECK constraints alike.
    </para>
   </refsect3>
  </refsect2>
  
  <refsect2 id="R2-SQL-PRIMARYKEY-1">
   <title>
    PRIMARY KEY Constraint
   </title>
   <synopsis>
[ CONSTRAINT <replaceable class="PARAMETER">constraint_name</replaceable> ] PRIMARY KEY 
   </synopsis>
d400 8
a407 15
   <refsect3>
    <title>Inputs</title>
    <para>
     <variablelist>
      <varlistentry>
       <term><replaceable class="PARAMETER">constraint_name</replaceable></term>
       <listitem>
	<para>
	 An arbitrary name given to a constraint clause.
	</para>
       </listitem>
      </varlistentry>
     </variablelist>
    </para>
   </refsect3>
d409 10
a418 16
   <refsect3>
    <title>Outputs</title>
    <variablelist>
     <varlistentry>
      <term><computeroutput>
ERROR: Cannot insert a duplicate key into a unique index.
       </computeroutput></term>
      <listitem>
       <para>
	This occurs at runtime if one tries to insert a duplicate value into
	a column subject to a PRIMARY KEY constraint.
       </para>
      </listitem>
     </varlistentry>
    </variablelist>
   </refsect3>
d420 8
a427 14
   <refsect3>
    <title>Description</title>
    <para>
     The PRIMARY KEY column constraint specifies that a column of a
     table may contain only unique (non-duplicate), non-NULL values. The
     definition of the specified column does not have to include an
     explicit NOT NULL constraint to be included in a PRIMARY KEY
     constraint.
    </para>
    <para>
     Only one PRIMARY KEY can be specified for a table, whether as a
     column constraint or a table constraint.
    </para>
   </refsect3>
d429 10
a438 19
   <refsect3 id="R3-SQL-PRIMARYKEY-3">
    <title>
     Notes
    </title>
    <para>
     <productname>Postgres</productname> automatically creates
     a unique index to assure
     data integrity (see CREATE INDEX statement).
    </para>
    <para>
     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, since it will result in duplication
     of equivalent indexes and unproductive additional runtime overhead.
     However, <productname>Postgres</productname> does not specifically
     disallow this.
    </para>
   </refsect3>
  </refsect2>
d440 18
a457 21
  <refsect2 id="R2-SQL-REFERENCES-1">
   <refsect2info>
    <date>2000-02-04</date>
   </refsect2info>
   <title>
    REFERENCES Constraint
   </title>
   <synopsis>
[ CONSTRAINT <replaceable class="parameter">constraint_name</replaceable> ] REFERENCES <replaceable class="parameter">reftable</replaceable> [ ( <replaceable class="parameter">refcolumn</replaceable> ) ] 
    [ MATCH <replaceable class="parameter">matchtype</replaceable> ]
    [ ON DELETE <replaceable class="parameter">action</replaceable> ] 
    [ ON UPDATE <replaceable class="parameter">action</replaceable> ]
    [ [ NOT ] DEFERRABLE ] 
    [ INITIALLY <replaceable class="parameter">checktime</replaceable> ]
   </synopsis>
   <para>
    The REFERENCES constraint specifies a rule that a column
    value is checked against the values of another column.
    REFERENCES can also be specified as part of
    a FOREIGN KEY table constraint.
   </para>
d459 30
a488 2
   <refsect3 id="R3-SQL-REFERENCES-1">
    <title>Inputs</title>
d490 6
a495 193
    <para>
     <variablelist>
      <varlistentry>
       <term><replaceable class="PARAMETER">constraint_name</replaceable></term>
       <listitem>
	<para>
	 An arbitrary name given to a constraint clause.
	</para>
       </listitem>
      </varlistentry>

      <varlistentry>
       <term><replaceable class="parameter">reftable</replaceable></term>
       <listitem>
        <para>
         The table that contains the data to check against.
        </para>
       </listitem>
      </varlistentry>

      <varlistentry>
       <term><replaceable class="parameter">refcolumn</replaceable></term>
       <listitem>
        <para>
         The column in <replaceable class="parameter">reftable</replaceable>
         to check the data against.  If this is not specified, the PRIMARY KEY of the
         <replaceable class="parameter">reftable</replaceable> is used.
        </para>
       </listitem>
      </varlistentry>
      <varlistentry>
       <term>MATCH <replaceable class="parameter">matchtype</replaceable></term>
       <listitem>
        <para>
         There are three match types: MATCH FULL, MATCH PARTIAL, and a
         default match type if none is specified. MATCH FULL will not
         allow one column of a multi-column foreign key to be NULL
         unless all foreign key columns are NULL. The default MATCH type
         allows some foreign key columns to be NULL while other parts
         of the foreign key are not NULL. MATCH PARTIAL is currently not
	 supported.
        </para>
       </listitem>
      </varlistentry>
      <varlistentry>
       <term>ON DELETE <replaceable class="parameter">action</replaceable></term>
       <listitem>
        <para>
	 The action to do when a referenced row in the referenced table is being
         deleted.  There are the following actions.
         <variablelist>
          <varlistentry>
           <term>NO ACTION</term>
           <listitem>
            <para>
             Produce error if foreign key violated.  This is the default.
            </para>
           </listitem>
          </varlistentry>
          <varlistentry>
           <term>RESTRICT</term>
           <listitem>
            <para>
             Same as NO ACTION.
            </para>
           </listitem>
          </varlistentry>
          <varlistentry>
           <term>CASCADE</term>
           <listitem>
            <para>
             Delete any rows referencing the deleted row.
            </para>
           </listitem>
          </varlistentry>
          <varlistentry>
           <term>SET NULL</term>
           <listitem>
            <para>
             Set the referencing column values to NULL.
            </para>
           </listitem>
          </varlistentry>
          <varlistentry>
           <term>SET DEFAULT</term>
           <listitem>
            <para>
             Set the referencing column values to their default value.
            </para>
           </listitem>
          </varlistentry>
         </variablelist>
        </para>
       </listitem>
      </varlistentry>      
      <varlistentry>
       <term>ON UPDATE <replaceable class="parameter">action</replaceable></term>
       <listitem>
        <para>
	 The action to do 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 changed, no action is done.
	 There are the following actions.
         <variablelist>
          <varlistentry>
           <term>NO ACTION</term>
           <listitem>
            <para>
             Produce error if foreign key violated.  This is the default.
            </para>
           </listitem>
          </varlistentry>
          <varlistentry>
           <term>RESTRICT</term>
           <listitem>
            <para>
             Same as NO ACTION.
            </para>
           </listitem>
          </varlistentry>
          <varlistentry>
           <term>CASCADE</term>
           <listitem>
            <para>
             Update the value of the referencing column to the new value of the
             referenced column.
            </para>
           </listitem>
          </varlistentry>
          <varlistentry>
           <term>SET NULL</term>
           <listitem>
            <para>
             Set the referencing column values to NULL.
            </para>
           </listitem>
          </varlistentry>
          <varlistentry>
           <term>SET DEFAULT</term>
           <listitem>
            <para>
             Set the referencing column values to their default value.
            </para>
           </listitem>
          </varlistentry>
         </variablelist>
        </para>
       </listitem>
      </varlistentry>

      <varlistentry>
       <term> [ NOT ] DEFERRABLE </term>
       <listitem>
        <para>
         This controls whether the constraint can be deferred to the end
         of the transaction. If DEFERRABLE, SET CONSTRAINTS ALL DEFERRED
         will cause the foreign key to be checked only at the end of the
         transaction. NOT DEFERRABLE is the default.
        </para>
       </listitem>
      </varlistentry>

      <varlistentry>
       <term>INITIALLY <replaceable class="parameter">checktime</replaceable></term>
       <listitem>
        <para>
         <replaceable class="parameter">checktime</replaceable> has two possible values 
         which specify the default time to check the constraint.
         <variablelist>
          <varlistentry>
           <term>DEFERRED</term>
	   <listitem>
	    <para>
	     Check constraint only at the end of the transaction.
	    </para>
	   </listitem>
          </varlistentry>
          <varlistentry>
           <term>IMMEDIATE</term>
	   <listitem>
	    <para>
	     Check constraint after each statement. This is the default.
	    </para>
	   </listitem>
	  </varlistentry>
         </variablelist>
        </para>
       </listitem>
      </varlistentry>
     </variablelist>
    </para>
   </refsect3>
   
a496 34
   <refsect3 id="R3-SQL-REFERENCES-2">
    <refsect3info>
     <date>2000-02-04</date>
    </refsect3info>
    <title>
     Outputs
    </title>
    <para>
     <variablelist>
      <varlistentry>
       <term><replaceable>status</replaceable></term>
       <listitem>
	<para>
	 <variablelist>
	  <varlistentry>
	   <term><computeroutput>
ERROR:  <replaceable class="parameter">name</replaceable> referential integrity violation - key referenced from 
<replaceable class="parameter">table</replaceable> not found in <replaceable class="parameter">reftable</replaceable>
	    </computeroutput></term>
	   <listitem>
	    <para>
             This error occurs at runtime if one tries to insert a value
             into a column which does not have a matching column in the
             referenced table.
	    </para>
	   </listitem>
	  </varlistentry>
	 </variablelist>
	</para>
       </listitem>
      </varlistentry>
     </variablelist> 
    </para>
   </refsect3>
d498 8
a505 14
   <refsect3 id="R3-SQL-REFERENCES-3">
    <title>Description</title>
    <para>
     The REFERENCES column constraint specifies that a
     column of a table must only contain values which match against
     values in a referenced column of a referenced table.
    </para>
    <para>
     A value added to this column is matched against the values of the
     referenced table and referenced column using the given match type.
     In addition, when the referenced column data is changed, actions
     are run upon this column's matching data.
    </para>
   </refsect3>
d507 12
a518 16
   <refsect3 id="R3-SQL-REFERENCES-4">
    <refsect3info>
     <date>1998-09-11</date>
    </refsect3info>
    <title>
     Notes
    </title>
    <para>
     Currently <productname>Postgres</productname> only supports MATCH
     FULL and a default match type. In addition, the referenced
     columns are supposed to be the columns of a UNIQUE constraint in
     the referenced table, however <productname>Postgres</productname>
     does not enforce this.
    </para>
   </refsect3>
  </refsect2>
a519 22
 
 <refsect1 id="R1-SQL-TABLECONSTRAINT-1">
  <title>
   Table Constraints
  </title>
  <para>
   <synopsis>
[ CONSTRAINT name ] { PRIMARY KEY |  UNIQUE } ( <replaceable class="parameter">column</replaceable> [, ... ] )
[ CONSTRAINT name ] CHECK ( <replaceable>constraint</replaceable> )
[ CONSTRAINT name ] FOREIGN KEY ( <replaceable class="parameter">column</replaceable> [, ... ] ) 
                     REFERENCES <replaceable class="parameter">reftable</replaceable> [ ( <replaceable class="parameter">refcolumn</replaceable> [, ... ] ) ]
                      [ MATCH <replaceable class="parameter">matchtype</replaceable> ] 
                      [ ON DELETE <replaceable class="parameter">action</replaceable> ] 
                      [ ON UPDATE <replaceable class="parameter">action</replaceable> ]
                      [ [ NOT ] DEFERRABLE ] 
                      [ INITIALLY <replaceable class="parameter">checktime</replaceable> ]
   </synopsis>
  </para>
  <refsect2 id="R2-SQL-TABLECONSTRAINT-1">
   <title>
    Inputs
   </title>
a520 1
   <para>
d522 2
a523 89
    <variablelist>
     <varlistentry>
      <term><replaceable class="parameter">constraint_name</replaceable></term>
      <listitem>
       <para>
	An arbitrary name given to a constraint clause.
       </para>
      </listitem>
     </varlistentry>
     <varlistentry>
      <term><replaceable class="parameter">column</replaceable> [, ... ]</term>
      <listitem>
       <para>
	The column name(s) for which to define a unique index
	and, for PRIMARY KEY, a NOT NULL constraint.
       </para>
      </listitem>
     </varlistentry>
     <varlistentry>
      <term>CHECK ( <replaceable class="parameter">constraint</replaceable> )</term>
      <listitem>
       <para>
	A boolean expression to be evaluated as the constraint.
       </para>
      </listitem>
     </varlistentry>
    </variablelist>
   </para>
  </refsect2>
    
  <refsect2 id="R2-SQL-TABLECONSTRAINT-2">
   <title>
    Outputs
   </title>
   
   <para>
    The possible outputs for the table constraint clause are the same
    as for the corresponding portions of the column constraint clause.
   </para>
  </refsect2>
  
  <refsect2 id="R2-SQL-TABLECONSTRAINT-3">
   <title>
    Description
   </title>
   
   <para>
    A table constraint is an integrity constraint defined on one or
    more columns of a table. The four variations of <quote>Table
    Constraint</quote> are:
    <simplelist columns="1">
     <member>UNIQUE</member>
     <member>CHECK</member>
     <member>PRIMARY KEY</member>
     <member>FOREIGN KEY</member>
    </simplelist>
   </para>
  </refsect2>
 
  <refsect2 id="R2-SQL-UNIQUECLAUSE-4">
   <title>
    UNIQUE Constraint
   </title>
   <para>
    <synopsis>
[ CONSTRAINT <replaceable class="parameter">constraint_name</replaceable> ] UNIQUE ( <replaceable class="parameter">column</replaceable> [, ... ] )
    </synopsis>
   </para>
   <refsect3>
    <title>Inputs</title>
    <variablelist>
     <varlistentry>
      <term><replaceable class="parameter">constraint_name</replaceable></term>
      <listitem>
       <para>
	An arbitrary name given to a constraint clause.
       </para>
      </listitem>
     </varlistentry>
     <varlistentry>
      <term><replaceable class="parameter">column</replaceable></term>
      <listitem>
       <para>
	A name of a column in a table.
       </para>
      </listitem>
     </varlistentry>
    </variablelist>
   </refsect3>
d525 2
a526 2
   <refsect3>
    <title>Outputs</title>
d528 12
a539 20
     <variablelist>
      <varlistentry>
       <term><replaceable>status</replaceable></term>
       <listitem>
	<para>
	 <variablelist>
	  <varlistentry>
	   <term>ERROR: Cannot insert a duplicate key into a unique index</term>
	   <listitem>
	    <para>
	     This error occurs at runtime if one tries to insert a
	     duplicate value into a column.
	    </para>
	   </listitem>
	  </varlistentry>
	 </variablelist>
	</para>
       </listitem>
      </varlistentry>
     </variablelist>
a540 18
   </refsect3>
   
   <refsect3>
    <title>
     Description
    </title>
    
    <para>
     The UNIQUE constraint specifies a rule that a group of one or more
     distinct columns of a table may 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.
    </para>
    <para>
     See the section on the UNIQUE column constraint for more details.
    </para>
   </refsect3>
d542 10
a551 5
   <refsect3 id="R3-SQL-UNIQUECLAUSE-4">
    <title>
     Usage
    </title>
    
d553 5
a557 8
     Prevent duplicate rows in the table distributors:
     <programlisting>
CREATE TABLE distributors (
    did      DECIMAL(3),
    name     VARCHAR(40),
    UNIQUE(did,name)
);
     </programlisting>
d559 1
a559 2
   </refsect3>
  </refsect2>
d561 1
a561 11
  <refsect2 id="R2-SQL-PRIMARYKEY-4">
   <title>
    PRIMARY KEY Constraint
   </title>
   <para>
    <synopsis>
[ CONSTRAINT <replaceable class="PARAMETER">constraint_name</replaceable> ] PRIMARY KEY ( <replaceable class="PARAMETER">column</replaceable> [, ... ] ) 
    </synopsis>
   </para>
   <refsect3>
    <title>Inputs</title>
d563 6
a568 54

     <variablelist>
      <varlistentry>
       <term><replaceable class="PARAMETER">constraint_name</replaceable></term>
       <listitem>
	<para>
	 An arbitrary name given to a constraint clause.
	</para>
       </listitem>
      </varlistentry>
      <varlistentry>
       <term><replaceable class="PARAMETER">column</replaceable> [, ... ]</term>
       <listitem>
	<para>
	 The names of one or more columns in the table.
	</para>
       </listitem>
      </varlistentry>
     </variablelist>
    </para>
   </refsect3>
   
   <refsect3>
    <title>Outputs</title>
    <variablelist>
     <varlistentry>
      <term><replaceable>status</replaceable></term>
      <listitem>
       <para>
	<variablelist>
	 <varlistentry>
	  <term>ERROR: Cannot insert a duplicate key into a unique index.</term>
	  <listitem>
	   <para>
	    This occurs at run-time if one tries to insert a duplicate
	    value into a column subject to a PRIMARY KEY constraint.
	   </para>
	  </listitem>
	 </varlistentry>
	</variablelist>
       </para>
      </listitem>
     </varlistentry>
    </variablelist>
   </refsect3>
   
   <refsect3>
    <title>Description</title>
    <para>
     The PRIMARY KEY constraint specifies a rule that a group of one
     or more distinct columns of a table may contain only unique
     (nonduplicate), non-null values. The column definitions of
     the specified columns do not have to include a NOT NULL
     constraint to be included in a PRIMARY KEY constraint.
d570 1
d572 1
d574 3
a576 2
     The PRIMARY KEY table constraint is similar to that for column constraints,
     with the additional capability of encompassing multiple columns.
d578 3
a580 6
    <para>
     Refer to the section on the PRIMARY KEY column constraint for more
     information.
    </para>
   </refsect3>
  </refsect2>
a581 21
  <refsect2 id="R2-SQL-REFERENCES-2">
   <refsect2info>
    <date>2000-02-04</date>
   </refsect2info>
   <title>
    REFERENCES Constraint
   </title>
   <synopsis>
[ CONSTRAINT <replaceable class="parameter">constraint_name</replaceable> ] FOREIGN KEY ( <replaceable class="parameter">column</replaceable> [, ... ] )
    REFERENCES <replaceable class="parameter">reftable</replaceable> [ ( <replaceable class="parameter">refcolumn</replaceable> [, ... ] ) ] 
    [ MATCH <replaceable class="parameter">matchtype</replaceable> ]
    [ ON DELETE <replaceable class="parameter">action</replaceable> ] 
    [ ON UPDATE <replaceable class="parameter">action</replaceable> ]
    [ [ NOT ] DEFERRABLE ]
    [ INITIALLY <replaceable class="parameter">checktime</replaceable> ]
   </synopsis>
   <para>
    The REFERENCES constraint specifies a rule that a column value or set
    of column values is
    checked against the values in another table.
   </para>
d583 2
a584 240
   <refsect3 id="R3-SQL-REFERENCES-5">
    <title>Inputs</title>
    <para>
     <variablelist>
      <varlistentry>
       <term><replaceable class="PARAMETER">constraint_name</replaceable></term>
       <listitem>
	<para>
	 An arbitrary name given to a constraint clause.
	</para>
       </listitem>
      </varlistentry>
      <varlistentry>
       <term><replaceable class="PARAMETER">column</replaceable> [, ... ]</term>
       <listitem>
	<para>
	 The names of one or more columns in the table.
	</para>
       </listitem>
      </varlistentry>
      <varlistentry>
       <term><replaceable class="parameter">reftable</replaceable></term>
       <listitem>
        <para>
         The table that contains the data to check against.
        </para>
       </listitem>
      </varlistentry>
      <varlistentry>
       <term><replaceable class="parameter">referenced column</replaceable> [, ... ]</term>
       <listitem>
        <para>
         One or more columns in the <replaceable class="parameter">reftable</replaceable>
         to check the data against.  If this is not specified, the PRIMARY KEY of the
         <replaceable class="parameter">reftable</replaceable> is used.
        </para>
       </listitem>
      </varlistentry>
      <varlistentry>
       <term>MATCH <replaceable class="parameter">matchtype</replaceable></term>
       <listitem>
        <para>
         There are three match types: MATCH FULL, MATCH PARTIAL, and a
         default match type if none is specified. MATCH FULL will not
         allow one column of a multi-column foreign key to be NULL
         unless all foreign key columns are NULL. The default MATCH type
         allows some foreign key columns to be NULL while other parts
         of the foreign key are not NULL. MATCH PARTIAL is currently not
	 supported.
        </para>
       </listitem>
      </varlistentry>
      <varlistentry>
       <term>ON DELETE <replaceable class="parameter">action</replaceable></term>
       <listitem>
        <para>
	 The action to do when a referenced row in the referenced table is being
         deleted.  There are the following actions.
         <variablelist>
          <varlistentry>
           <term>NO ACTION</term>
           <listitem>
            <para>
             Produce error if foreign key violated.  This is the default.
            </para>
           </listitem>
          </varlistentry>
          <varlistentry>
           <term>RESTRICT</term>
           <listitem>
            <para>
             Same as NO ACTION.
            </para>
           </listitem>
          </varlistentry>
          <varlistentry>
           <term>CASCADE</term>
           <listitem>
            <para>
             Delete any rows referencing the deleted row.
            </para>
           </listitem>
          </varlistentry>
          <varlistentry>
           <term>SET NULL</term>
           <listitem>
            <para>
             Set the referencing column values to NULL.
            </para>
           </listitem>
          </varlistentry>
          <varlistentry>
           <term>SET DEFAULT</term>
           <listitem>
            <para>
             Set the referencing column values to their default value.
            </para>
           </listitem>
          </varlistentry>
         </variablelist>
        </para>
       </listitem>
      </varlistentry>      
      <varlistentry>
       <term>ON UPDATE <replaceable class="parameter">action</replaceable></term>
       <listitem>
        <para>
	 The action to do 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 changed, no action is done.
	 There are the following actions.
         <variablelist>
          <varlistentry>
           <term>NO ACTION</term>
           <listitem>
            <para>
             Produce error if foreign key violated.  This is the default.
            </para>
           </listitem>
          </varlistentry>
          <varlistentry>
           <term>RESTRICT</term>
           <listitem>
            <para>
             Disallow update of row being referenced.
            </para>
           </listitem>
          </varlistentry>
          <varlistentry>
           <term>CASCADE</term>
           <listitem>
            <para>
             Update the value of the referencing column to the new value
             of the referenced column.
            </para>
           </listitem>
          </varlistentry>
          <varlistentry>
           <term>SET NULL</term>
           <listitem>
            <para>
             Set the referencing column values to NULL.
            </para>
           </listitem>
          </varlistentry>
          <varlistentry>
           <term>SET DEFAULT</term>
           <listitem>
            <para>
             Set the referencing column values to their default value.
            </para>
           </listitem>
          </varlistentry>
         </variablelist>
        </para>
       </listitem>
      </varlistentry>
      <varlistentry>
       <term> [ NOT ] DEFERRABLE </term>
       <listitem>
        <para>
         This controls whether the constraint can be deferred to the end
         of the transaction. If DEFERRABLE, SET CONSTRAINTS ALL DEFERRED
         will cause the foreign key to be checked only at the end of the
         transaction. NOT DEFERRABLE is the default.
        </para>
       </listitem>
      </varlistentry>
      <varlistentry>
       <term>INITIALLY <replaceable class="parameter">checktime</replaceable></term>
       <listitem>
        <para>
         <replaceable class="parameter">checktime</replaceable> has two
         possible values which specify the default time to check the
         constraint.
         <variablelist>
          <varlistentry>
           <term>IMMEDIATE</term>
	   <listitem>
	    <para>
	     Check constraint after each statement. This is the default.
	    </para>
	   </listitem>
          </varlistentry>
          <varlistentry>
           <term>DEFERRED</term>
	   <listitem>
	    <para>
	     Check constraint only at the end of the transaction.
	    </para>
	   </listitem>
          </varlistentry>
         </variablelist>
        </para>
       </listitem>
      </varlistentry>
     </variablelist>
    </para>
   </refsect3>
   <refsect3 id="R3-SQL-REFERENCES-6">
    <refsect3info>
     <date>2000-02-04</date>
    </refsect3info>
    <title>
     Outputs
    </title>
    <para>
     <variablelist>
      <varlistentry>
       <term><replaceable>status</replaceable></term>
       <listitem>
	<para>
	 <variablelist>
	  <varlistentry>
	   <term><computeroutput>
ERROR:  <replaceable class="parameter">name</replaceable> referential integrity violation - key referenced from 
<replaceable class="parameter">table</replaceable> not found in <replaceable class="parameter">reftable</replaceable>
	    </computeroutput></term>
	   <listitem>
	    <para>
             This error occurs at runtime if one tries to insert a value
             into a column which does not have a matching column in the
             referenced table.
	    </para>
	   </listitem>
	  </varlistentry>
	 </variablelist>
	</para>
       </listitem>
      </varlistentry>
     </variablelist> 
    </para>
   </refsect3>
   <refsect3>
    <title>Description</title>
    <para>
     The FOREIGN KEY constraint specifies a rule that a group of one
     or more distinct columns of a table is related to a group
     of distinct columns in the referenced table.
    </para>
a585 19
    <para>
     The FOREIGN KEY table constraint is similar to that for column
     constraints, with the additional capability of encompassing
     multiple columns.
    </para>
    <para>
     Refer to the section on the FOREIGN KEY column constraint for more
     information.
    </para>
   </refsect3>
   
  </refsect2>

 </refsect1>
 
 <refsect1 id="R1-SQL-CREATETABLE-2">
  <title>
   Usage
  </title>
d587 2
a588 1
   Create table films and table distributors:
d590 1
a590 1
   <programlisting>
d592 6
a597 6
     code      CHARACTER(5) CONSTRAINT firstkey PRIMARY KEY,
     title     CHARACTER VARYING(40) NOT NULL,
     did       DECIMAL(3) NOT NULL,
     date_prod DATE,
     kind      CHAR(10),
     len       INTERVAL HOUR TO MINUTE
d599 1
a599 1
   </programlisting>
d601 1
a601 1
   <programlisting>
d603 2
a604 2
     did      DECIMAL(3) PRIMARY KEY DEFAULT NEXTVAL('serial'),
     name     VARCHAR(40) NOT NULL CHECK (name &lt;&gt; '')
d606 1
a606 1
   </programlisting>
d612 5
a616 5
   <programlisting>
   CREATE TABLE array (
          vector INT[][]
          );
   </programlisting>
d620 2
a621 3
   Define a UNIQUE table constraint for the table films.
   UNIQUE table constraints can be defined on one or more
   columns of the table:
d623 1
a623 1
   <programlisting>
d625 6
a630 6
    code      CHAR(5),
    title     VARCHAR(40),
    did       DECIMAL(3),
    date_prod DATE,
    kind      CHAR(10),
    len       INTERVAL HOUR TO MINUTE,
d633 1
a633 1
   </programlisting>
d637 1
a637 1
   Define a CHECK column constraint:
d639 1
a639 1
   <programlisting>
d641 2
a642 2
    did      DECIMAL(3) CHECK (did > 100),
    name     VARCHAR(40)
d644 1
a644 1
   </programlisting>
d648 1
a648 1
   Define a CHECK table constraint:
d650 1
a650 1
   <programlisting>
d652 3
a654 3
    did      DECIMAL(3),
    name     VARCHAR(40)
    CONSTRAINT con1 CHECK (did > 100 AND name > '')
d656 1
a656 1
   </programlisting>
d660 3
a662 3
   Define a PRIMARY KEY table constraint for the table films.
   PRIMARY KEY table constraints can be defined on one or more
   columns of the table:
d664 1
a664 1
   <programlisting>
d666 6
a671 6
    code      CHAR(5),
    title     VARCHAR(40),
    did       DECIMAL(3),
    date_prod DATE,
    kind      CHAR(10),
    len       INTERVAL HOUR TO MINUTE,
d674 1
a674 1
   </programlisting>
d678 4
a681 3
   Defines a PRIMARY KEY column constraint for table distributors.
   PRIMARY KEY column constraints can only be defined on one column
   of the table (the following two examples are equivalent):
d683 1
a683 1
   <programlisting>
d685 2
a686 2
    did      DECIMAL(3),
    name     CHAR VARYING(40),
d689 42
a730 1
   </programlisting>
d732 1
a732 1
   <programlisting>
d734 2
a735 2
    did      DECIMAL(3) PRIMARY KEY,
    name     VARCHAR(40)
d737 11
a747 1
   </programlisting>
d749 1
a749 1
  
d752 12
a763 9
 <refsect1 id="R1-SQL-CREATETABLE-3">
  <title>
   Compatibility
  </title>

  <refsect2 id="R2-SQL-CREATETABLE-4">
   <title>
    SQL92
   </title>
d765 3
a767 8
    In addition to the locally visible temporary table, SQL92 also defines a
    CREATE GLOBAL TEMPORARY TABLE statement, and optionally an 
    ON COMMIT clause:
   <synopsis>
CREATE GLOBAL TEMPORARY TABLE <replaceable class="parameter">table</replaceable> ( <replaceable class="parameter">column</replaceable> <replaceable class="parameter">type</replaceable> [
    DEFAULT <replaceable class="parameter">value</replaceable> ] [ CONSTRAINT <replaceable class="parameter">column_constraint</replaceable> ] [, ... ] )
    [ CONSTRAINT <replaceable class="parameter">table_constraint</replaceable> ] [ ON COMMIT { DELETE | PRESERVE } ROWS ] 
   </synopsis>
d771 12
a782 3
    For temporary tables, the CREATE GLOBAL TEMPORARY TABLE statement
    names a new table visible to other clients and defines the table's columns
    and constraints. 
d784 5
d790 6
a795 6
    The optional ON COMMIT clause of CREATE TEMPORARY TABLE specifies
    whether or not the temporary table should be emptied of rows
    whenever COMMIT is executed. If the ON COMMIT clause is omitted, SQL92
    specifies that the default is ON COMMIT DELETE ROWS.  However,
    <productname>Postgres</productname>' behavior is always like
    ON COMMIT PRESERVE ROWS.
d797 4
d802 6
a807 9
   <refsect3 id="R3-SQL-UNIQUECLAUSE-1">
    <title>
     UNIQUE clause
    </title>
    <para>
     SQL92 specifies some additional capabilities for UNIQUE:
    </para>
    <para>
     Table Constraint definition:
d809 4
a812 6
     <synopsis>
[ CONSTRAINT <replaceable>constraint_name</replaceable> ] UNIQUE ( <replaceable>column</replaceable> [, ... ] )
    [ { INITIALLY DEFERRED | INITIALLY IMMEDIATE } ]
    [ [ NOT ] DEFERRABLE ]
     </synopsis>
    </para>
d814 4
a817 63
    <para>
     Column Constraint definition:

     <synopsis>
[ CONSTRAINT <replaceable>constraint_name</replaceable> ] UNIQUE
      [ {INITIALLY DEFERRED | INITIALLY IMMEDIATE} ]
      [ [ NOT ] DEFERRABLE ]
     </synopsis>
    </para>
   </refsect3>
   
   <refsect3 id="R3-SQL-NULL-1">
    <title>
     NULL clause
    </title>
    <para>
	The NULL <quote>constraint</quote> (actually a non-constraint) is a
	<productname>Postgres</productname> extension to SQL92 that is
	included for symmetry with the NOT NULL clause (and for compatibility
	with some other RDBMSes). Since it is the
	default for any column, its presence is simply noise.
     <synopsis>
[ CONSTRAINT <replaceable>constraint_name</replaceable> ] NULL 
     </synopsis>
    </para>
   </refsect3>
   
   <refsect3 id="R3-SQL-NOTNULL-4">
    <title>
     NOT NULL clause
    </title>
    <para>
     
     SQL92 specifies some additional capabilities for NOT NULL:
     <synopsis>
[ CONSTRAINT <replaceable>constraint_name</replaceable> ] NOT NULL 
    [ {INITIALLY DEFERRED | INITIALLY IMMEDIATE} ]
    [ [ NOT ] DEFERRABLE ]
     </synopsis>
    </para>
   </refsect3>
   
<!--
I can't figure out why DEFAULT clause is different from what we already have.
Perhaps because CURRENT_USER and CURRENT_DATE have specific types (currently
the <type>name</type> type), if you aren't careful then the types won't match up with
the column. Not our problem...
- Thomas 1998-08-16

   <REFSECT3 ID="R3-SQL-DEFAULTCLAUSE-1">
    <TITLE>
     DEFAULT clause
    </TITLE>
    <PARA>
     SQL92 specifies some additional capabilities for the DEFAULT clause.
     A DEFAULT clause is used to set the default value for a column
     or a domain.
    </para>
    <synopsis>
DEFAULT niladic_user_function | niladic_datetime_function | NULL
    </synopsis>
   </refsect3>
-->
d819 1
a819 25
   <refsect3 id="R3-SQL-CONSTRAINT-3">
    <title>
     CONSTRAINT clause
    </title>
    <para>
     SQL92 specifies some additional capabilities for constraints,
     and also defines assertions and domain constraints.
     <note>
      <para>
       <productname>Postgres</productname> does not yet support 
       either domains or assertions.
      </para>
     </note>
    </para>
    <para>
     An assertion is a special type of integrity constraint and shares
     the same namespace as other constraints. However, an assertion is
     not necessarily dependent on one particular table as
     constraints are, so SQL-92 provides the CREATE ASSERTION statement
     as an alternate method for defining a constraint:
    </para>
    <synopsis>
CREATE ASSERTION <replaceable>name</replaceable> CHECK ( <replaceable>condition</replaceable> )
    </synopsis>
    
d833 4
d838 8
a845 19
    <para>
     Table constraint definition:

     <synopsis>
[ CONSTRAINT <replaceable>constraint_name</replaceable> ] { PRIMARY KEY ( <replaceable class="parameter">column</replaceable>, ... ) | FOREIGN KEY <replaceable>constraint</replaceable> | UNIQUE <replaceable>constraint</replaceable> | CHECK <replaceable>constraint</replaceable> }
    [ {INITIALLY DEFERRED | INITIALLY IMMEDIATE} ]
    [ [ NOT ] DEFERRABLE ]
     </synopsis>
    </para>

    <para>
     Column constraint definition:

     <synopsis>
[ CONSTRAINT <replaceable>constraint_name</replaceable> ] { NOT NULL | PRIMARY KEY | FOREIGN KEY <replaceable>constraint</replaceable> | UNIQUE | CHECK <replaceable>constraint</replaceable> }  
    [ {INITIALLY DEFERRED | INITIALLY IMMEDIATE} ]
    [ [ NOT ] DEFERRABLE ]
     </synopsis>
    </para>
d847 2
a848 80
    <para>
     A CONSTRAINT definition may contain one deferment attribute
     clause and/or one initial constraint mode clause, in any order.
     <variablelist>
      <varlistentry>
       <term>NOT DEFERRABLE</term>
       <listitem>
	<para>
         The constraint must be checked at the end of each statement.
         SET CONSTRAINTS ALL DEFERRED will have no effect on this type
         of constraint.
	</para>
       </listitem>
      </varlistentry>
      <varlistentry>
       <term>DEFERRABLE</term>
       <listitem>
	<para>
         This controls whether the constraint can be deferred to the end
         of the transaction. If SET CONSTRAINTS ALL DEFERRED is used or
         the constraint is set to INITIALLY DEFERRED, this will cause
         the foreign key to be checked only at the end of the
         transaction.
	</para>
        <note>
         <para>  
          <command>SET CONSTRAINTS</> changes the foreign key constraint mode
          only for the current transaction.
         </para>
        </note>
       </listitem>
      </varlistentry>
      <varlistentry>
       <term>INITIALLY IMMEDIATE</term>
       <listitem>
	<para>
	 Check constraint after each statement. This is the default.
	</para>
       </listitem>
      </varlistentry>
      <varlistentry>
       <term>INITIALLY DEFERRED</term>
       <listitem>
	<para>
         Check constraint only at the end of the transaction.
	</para>
       </listitem>
      </varlistentry>
     </variablelist>
    </para>
   </refsect3>
   
   
   <refsect3 id="R3-SQL-CHECK-4">
    <title>
     CHECK clause
    </title>
    <para>
     SQL92 specifies some additional capabilities for CHECK in either
table or column constraints.
    </para>
<!--
Constraints associated with domains do not need to be mentioned here,
even though it is the case that a domain constraint may possibly
affect a column or a table.
- Thomas 1998-08-16
    <para>
     A CHECK constraint is either a table constraint, a column
     constraint or a domain constraint.
    </para> 
-->
    <para>
     table constraint definition:
<synopsis>
[ CONSTRAINT <replaceable>constraint_name</replaceable> ]
      CHECK ( VALUE <replaceable>condition</replaceable> ) 
      [ {INITIALLY DEFERRED | INITIALLY IMMEDIATE} ]
      [ [ NOT ] DEFERRABLE ]
</synopsis>
    </para>
a849 10
    <para>
     column constraint definition:
<synopsis>
[ CONSTRAINT <replaceable>constraint_name</replaceable> ]
      CHECK ( VALUE <replaceable>condition</replaceable> ) 
      [ {INITIALLY DEFERRED | INITIALLY IMMEDIATE} ]
      [ [ NOT ] DEFERRABLE ]
</synopsis>
    </para>
<!--
d851 5
a855 21
     domain constraint definition: 
    </para>
    <synopsis>
     [ CONSTRAINT name] 
      CHECK ( VALUE condition ) 
      [ {INITIALLY DEFERRED | INITIALLY IMMEDIATE} ]
      [ [ NOT ] DEFERRABLE ]
    </synopsis>
    <para>
     CHECK domain constraints can be defined in either
     a CREATE DOMAIN statement or an ALTER DOMAIN statement:
    </para>
    <programlisting>
CREATE DOMAIN duration AS SMALLINT 
    CONSTRAINT minutes CHECK (VALUE IN (90,120,180,240)); 

ALTER DOMAIN cities 
    ADD CONSTRAINT new_city CHECK (VALUE LIKE 'L%');
   </programlisting>
-->
   </refsect3>
a856 24
   <refsect3 id="R3-SQL-PRIMARYKEY-1">
    <title>
     PRIMARY KEY clause
    </title>
    <para>
     SQL92 specifies some additional capabilities for PRIMARY KEY:
    </para>
    <para>
     Table Constraint definition:
     <synopsis>
[ CONSTRAINT <replaceable>constraint_name</replaceable> ] PRIMARY KEY ( <replaceable>column</replaceable> [, ... ] ) 
    [ {INITIALLY DEFERRED | INITIALLY IMMEDIATE} ]
    [ [ NOT ] DEFERRABLE ]
     </synopsis>
    </para>
    <para>
     Column Constraint definition: 
     <synopsis>
[ CONSTRAINT <replaceable>constraint_name</replaceable> ] PRIMARY KEY 
    [ {INITIALLY DEFERRED | INITIALLY IMMEDIATE} ]
    [ [ NOT ] DEFERRABLE ]
     </synopsis>
    </para>
   </refsect3>
d858 2
a859 12
   <refsect3 id="R3-SQL-INHERITANCE-1">
    <title>
     Inheritance
    </title>
    <para>
     Multiple inheritance via the INHERITS clause is a
     <productname>Postgres</productname> language extension.
     SQL99 (but not SQL92) defines single inheritance using a different
     syntax and different semantics.  SQL99-style inheritance is not yet
     supported by <productname>Postgres</productname>.
    </para>
   </refsect3>
d861 4
a864 12
   <refsect3 id="R3-SQL-OBJECTIDS-1">
    <title>
     Object IDs
    </title>
    <para>
     The <productname>Postgres</productname> concept of OIDs is not
     standard.  SQL99 (but not SQL92) has a notion of object ID, but
     the syntax and semantics are different --- SQL99 associates OIDs
     with individual values, not with rows.
    </para>
   </refsect3>
  </refsect2>
@


1.46
log
@Replace ASCII-quotes with proper markup.
@
text
@d2 1
a2 1
$Header: /home/projects/pgsql/cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v 1.45 2001/09/03 12:57:49 petere Exp $
d2081 3
a2083 2
     <synopsis>
[ CONSTRAINT <replaceable>constraint_name</replaceable> ] CHECK ( VALUE <replaceable>condition</replaceable> ) 
d2086 1
a2086 1
     </synopsis>
d2091 3
a2093 2
    <synopsis>
[ CONSTRAINT <replaceable>constraint_name</replaceable> ] CHECK ( VALUE <replaceable>condition</replaceable> ) 
d2096 1
a2096 1
    </synopsis>
@


1.45
log
@Put some kind of grammatical uniformity in the <refpurpose> lines.
@
text
@d2 1
a2 1
$Header: /home/projects/pgsql/cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v 1.44 2001/08/10 20:52:24 tgl Exp $
d239 1
a239 1
   into the current database. The table will be "owned" by the user issuing the
d1256 2
a1257 2
    more columns of a table. The four variations of "Table
    Constraint" are:
d1901 1
a1901 1
	The NULL "constraint" (actually a non-constraint) is a
d1930 1
a1930 1
the "name" type), if you aren't careful then the types won't match up with
@


1.44
log
@Cleanup some minor oversights in optional-OIDs stuff.
@
text
@d2 1
a2 1
$Header: /home/projects/pgsql/cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v 1.43 2001/08/10 18:57:32 tgl Exp $
d18 1
a18 1
   Creates a new table
@


1.43
log
@Make OIDs optional, per discussions in pghackers.  WITH OIDS is still the
default, but OIDS are removed from many system catalogs that don't need them.
Some interesting side effects: TOAST pointers are 20 bytes not 32 now;
pg_description has a three-column key instead of one.

Bugs fixed in passing: BINARY cursors work again; pg_class.relhaspkey
has some usefulness; pg_dump dumps comments on indexes, rules, and
triggers in a valid order.

initdb forced.
@
text
@d2 1
a2 1
$Header: /home/projects/pgsql/cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v 1.42 2001/05/03 17:50:55 tgl Exp $
d2158 1
a2158 1
   <refsect3 id="R3-SQL-INHERITANCE-1">
@


1.42
log
@Describe handling of multiply-inherited fields correctly.
@
text
@d2 1
a2 1
$Header: /home/projects/pgsql/cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v 1.41 2001/02/04 12:18:08 petere Exp $
d28 3
a30 2
      | <replaceable>table_constraint</replaceable> }  [, ... ]
    ) [ INHERITS ( <replaceable>parent_table</replaceable> [, ... ] ) ]
d113 12
d319 43
d2155 12
@


1.41
log
@When making xrefs to refsects, the linkend should point to the refsect and
the endterm to the title element, not both to the title.  At least
docbook2man prefers it that way.
@
text
@d2 1
a2 1
$Header: /home/projects/pgsql/cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v 1.40 2001/01/12 05:06:40 tgl Exp $
d29 1
a29 1
    ) [ INHERITS ( <replaceable>inherited_table</replaceable> [, ... ] ) ]
d102 1
a102 1
      <term><replaceable class="PARAMETER">inherited_table</replaceable></term>
a106 6
	If any inherited field name appears more than once, 
	<productname>Postgres</productname>
	reports an error.
	<productname>Postgres</productname> automatically allows the created
	table to inherit functions on tables above it in the inheritance
	hierarchy.
d256 17
d274 19
a292 6
   clause specifies a collection of table names from which this table
   automatically inherits all fields.  If any inherited field name
   appears more than once, Postgres reports an error.  Postgres automatically
   allows the created table to inherit functions on tables above it in
   the inheritance hierarchy.  Inheritance of functions is done according
   to the conventions of the Common Lisp Object System (CLOS).
d296 7
a302 3
   A table can have no more than 1600 columns (in practice, the
   effective limit is lower because of tuple-length constraints).
   A table cannot have the same name as a system catalog table.
@


1.40
log
@Bring CREATE TABLE syntax synopsis into line with reality; update a
bunch of old or poorly-worded documentation.
@
text
@d2 1
a2 1
$Header: /home/projects/pgsql/cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v 1.39 2001/01/05 06:34:16 tgl Exp $
d241 1
a241 1
   <xref linkend="R1-SQL-DEFAULTCLAUSE-1-TITLE" endterm="R1-SQL-DEFAULTCLAUSE-1-TITLE">.
@


1.39
log
@Remove not-really-standard implementation of CREATE TABLE's UNDER clause,
and revert documentation to describe the existing INHERITS clause
instead, per recent discussion in pghackers.  Also fix implementation
of SQL_inheritance SET variable: it is not cool to look at this var
during the initial parsing phase, only during parse_analyze().  See
recent bug report concerning misinterpretation of date constants just
after a SET TIMEZONE command.  gram.y really has to be an invariant
transformation of the query string to a raw parsetree; anything that
can vary with time must be done during parse analysis.
@
text
@d2 1
a2 1
$Header: /home/projects/pgsql/cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v 1.38 2000/12/30 19:00:11 petere Exp $
d23 1
a23 1
   <date>2001-01-04</date>
d26 22
a47 9
CREATE [ TEMPORARY | TEMP ] TABLE <replaceable class="PARAMETER">table</replaceable> (
    <replaceable class="PARAMETER">column</replaceable> <replaceable class="PARAMETER">type</replaceable>
    [ NULL | NOT NULL ] [ UNIQUE ] [ DEFAULT <replaceable class="PARAMETER">value</replaceable> ]
    [<replaceable>column_constraint_clause</replaceable> | PRIMARY KEY } [ ... ] ]
    [, ... ]
    [, PRIMARY KEY ( <replaceable class="PARAMETER">column</replaceable> [, ...] ) ]
    [, CHECK ( <replaceable class="PARAMETER">condition</replaceable> ) ]
    [, <replaceable>table_constraint_clause</replaceable> ]
    ) [ INHERITS ( <replaceable>inherited_table</replaceable> [, ...] ) ]
d59 1
a59 1
      <term>TEMPORARY</term>
d62 1
a62 1
	The table is created only for this session, and is
d65 3
a67 1
	while the temporary table exists.
d73 1
a73 1
      <term><replaceable class="PARAMETER">table</replaceable></term>
d82 1
a82 1
      <term><replaceable class="PARAMETER">column</replaceable></term>
d85 1
a85 1
	The name of a column.
d102 27
a128 1
      <term>DEFAULT <replaceable class="PARAMETER">value</replaceable></term>
d138 16
a153 1
      <term><replaceable>column_constraint_clause</replaceable></term>
d156 2
a157 10
	The optional column constraint clauses specify a list of
	integrity 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. Although
	<acronym>SQL92</acronym> requires the <replaceable
	class="PARAMETER">column_constraint_clause</replaceable> to
	refer to that column only, <productname>Postgres</productname>
	allows multiple columns to be referenced within a single column
	constraint. See the column constraint clause for more
	information.
d163 1
a163 1
      <term><replaceable>table_constraint_clause</replaceable></term>
d166 3
a168 10
	The optional table CONSTRAINT clause specifies a
	list of integrity constraints which new or updated entries must
	satisfy for an insert or update operation to succeed. Each
	constraint must evaluate to a boolean expression. Multiple
	columns may be referenced within a single constraint. Only one
	PRIMARY KEY clause may be specified for a table;
	PRIMARY KEY <replaceable>column</replaceable> (a table
	constraint) and PRIMARY KEY (a column constraint)
	are mutually exclusive. See the table constraint clause for
	more information.
d174 1
a174 1
      <term>INHERITS <replaceable class="PARAMETER">inherited_table</replaceable></term>
d177 2
a178 8
	The optional INHERITS clause specifies a list of table
	names from which this table automatically inherits all fields.
	If any inherited field name appears more than once, 
	<productname>Postgres</productname>
	reports an error.
	<productname>Postgres</productname> automatically allows the created
	table to inherit functions on tables above it in the inheritance
	hierarchy.
a219 12

     <varlistentry>
      <term><computeroutput>
ERROR:  DEFAULT: type mismatched
       </computeroutput></term>
      <listitem>
       <para>
	If data type of default value doesn't match the
	column definition's data type.
       </para>
      </listitem>
     </varlistentry>
d231 2
a232 2
   <command>CREATE TABLE</command> will enter a new table
   into the current data base. The table will be "owned" by the user issuing the
d255 7
a271 9
   Each new table <replaceable class="PARAMETER">table</replaceable>
   is automatically created as a type.  Therefore, one or more rows
   from the table are automatically a type and can be used in 
   <xref linkend="sql-altertable" endterm="sql-altertable-title">
   or other <command>CREATE TABLE</command> statements.
  </para>

  <para>
   The new table is created as a heap with no initial data.
a286 5
  <refsect2 id="R2-SQL-DEFAULTCLAUSE-1">
   <title>
    Inputs
   </title>
   <para>
d288 14
a301 29
    <variablelist>
     <varlistentry>
      <term><replaceable class="parameter">value</replaceable></term>
      <listitem>
       <para>
	The possible values for the default value expression are:
	<itemizedlist>
	 <listitem>
	  <simpara>
	   a literal value
	  </simpara>
	 </listitem>
	 <listitem>
	  <simpara>
	   a user function
	  </simpara>
	 </listitem>
	 <listitem>
	  <simpara>
	   a niladic function
	  </simpara>
	 </listitem>
	</itemizedlist>
       </para>
      </listitem>
     </varlistentry>	
    </variablelist>
   </para>
  </refsect2>
a304 87
    Outputs
   </title>
   <para>
    None.
   </para>
  </refsect2>
  
  <refsect2 id="R2-SQL-DEFAULTCLAUSE-3">
   <title>
    Description
   </title>
   <para>
    The DEFAULT clause assigns a default data value to a column
    (via a column definition in the CREATE TABLE statement). 
    The data type of a default value must match the column definition's
    data type.
   </para>
   <para>
    An INSERT operation that includes a column without a specified
    default value will assign the NULL value to the column
    if no explicit data value is provided for it.
    Default <replaceable class="parameter">literal</replaceable> means
    that the default is the specified constant value.
    Default <replaceable class="parameter">niladic-function</replaceable>
    or <replaceable class="parameter">user-function</replaceable> means
    that the default
    is the value of the specified function at the time of the INSERT.
   </para>
   <para>
    There are two types of niladic functions:
    <variablelist>
     <varlistentry>
      <term>niladic USER</term>
      <listitem>
       <variablelist>
	<varlistentry>
	 <term>CURRENT_USER / USER</term>
	 <listitem>
	  <simpara>See CURRENT_USER function</simpara>
	 </listitem>
	</varlistentry>
	<varlistentry>
	 <term>SESSION_USER</term>
	 <listitem>
	  <simpara>See CURRENT_USER function</simpara>
	 </listitem>
	</varlistentry>
	<varlistentry>
	 <term>SYSTEM_USER</term>
	 <listitem>
	  <simpara>Not implemented</simpara>
	 </listitem>
	</varlistentry>
       </variablelist>
      </listitem>
     </varlistentry>
     <varlistentry>
      <term>niladic datetime</term>
      <listitem>
       <variablelist>
	<varlistentry>
	 <term>CURRENT_DATE</term>
	 <listitem>
	  <simpara>See CURRENT_DATE function</simpara>
	 </listitem>
	</varlistentry>
	<varlistentry>
	 <term>CURRENT_TIME</term>
	 <listitem>
	  <simpara>See CURRENT_TIME function</simpara>
	 </listitem>
	</varlistentry>
	<varlistentry>
	 <term>CURRENT_TIMESTAMP</term>
	 <listitem>
	  <simpara>See CURRENT_TIMESTAMP function</simpara>
	 </listitem>
	</varlistentry>
       </variablelist>
      </listitem>
     </varlistentry>
    </variablelist>
   </para>

  </refsect2>
  <refsect2 id="R2-SQL-DEFAULTCLAUSE-4">
   <title>
a308 4
    To assign a constant value as the default for the
    columns <literal>did</literal> and <literal>number</literal>,
    and a string literal to the column <literal>did</literal>:

d310 4
a313 4
CREATE TABLE video_sales (
    did      VARCHAR(40) DEFAULT 'luso films',
    number   INTEGER DEFAULT 0,
    total    CASH DEFAULT '$0.0'
d316 5
d322 1
d324 1
a324 4
    To assign an existing sequence
    as the default for the column <literal>did</literal>,
    and a literal to the column <literal>name</literal>:

d326 1
a326 4
CREATE TABLE distributors (
    did      DECIMAL(3)  DEFAULT NEXTVAL('serial'),
    name     VARCHAR(40) DEFAULT 'luso films'
);
d328 5
d339 1
a339 1
   Column CONSTRAINT Clause
d343 4
a346 5
[ CONSTRAINT <replaceable class="parameter">name</replaceable> ] { [
    NULL | NOT NULL ] | UNIQUE | PRIMARY KEY | CHECK <replaceable
     class="parameter">constraint</replaceable> | REFERENCES 
     <replaceable class="parameter">reftable</replaceable>
     (<replaceable class="parameter">refcolumn</replaceable>)
a351 1
    [, ...]
d363 1
a363 1
      <term><replaceable class="parameter">name</replaceable></term>
d366 1
a366 5
	An arbitrary name given to the integrity constraint. 
	If <replaceable class="parameter">name</replaceable> is not specified,
	it is generated from the table and column names,
	which should ensure uniqueness for
	<replaceable class="parameter">name</replaceable>.
d396 1
a396 1
	this is enforced by an implicit creation of a unique index on the table.
d405 3
a407 3
	This column is a primary key, which implies that uniqueness is
	enforced by the system and that other tables may rely on this
	column as a unique identifier for rows. See PRIMARY KEY for more
d415 1
a415 1
<replaceable class="parameter">constraint</replaceable>
d419 1
a419 1
	The definition of the constraint.
d434 2
a435 5
    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. The use of PRIMARY KEY as a table constraint is mutually
    incompatible with PRIMARY KEY as a column constraint.
d441 1
a441 1
    UPDATE or DELETE operations performed on a Base Table. 
d524 1
a524 1
     one of which being a named constraint:
d541 1
a541 1
[ CONSTRAINT <replaceable class="parameter">name</replaceable> ] UNIQUE
d550 1
a550 1
       <term>CONSTRAINT <replaceable class="parameter">name</replaceable></term>
d553 1
a553 1
	 An arbitrary label given to a constraint.
d627 1
a627 3
     Defines a UNIQUE column constraint for the table distributors.
     UNIQUE column constraints can only be defined on one column
     of the table:
d652 1
a652 2
[ CONSTRAINT <replaceable class="parameter">name</replaceable> ] CHECK
    ( <replaceable>condition</replaceable> [, ...] ) 
d660 1
a660 1
       <term><replaceable class="parameter">name</replaceable></term>
d663 1
a663 1
	 An arbitrary name given to a constraint.
d694 1
a694 1
ERROR:  ExecAppend: rejected due to CHECK constraint "<replaceable class="parameter">table_column</replaceable>".
d714 1
a714 1
     The CHECK constraint specifies a restriction on allowed values
d719 14
a732 3
     The SQL92 CHECK column constraints can only be defined on, and
     refer to, one column of the table.
     <productname>Postgres</productname> does not have this restriction.
d742 1
a742 1
[ CONSTRAINT <replaceable class="PARAMETER">name</replaceable> ] PRIMARY KEY 
d750 1
a750 1
       <term>CONSTRAINT <replaceable class="PARAMETER">name</replaceable></term>
d753 1
a753 1
	 An arbitrary name for the constraint.
d788 2
a789 1
     Only one PRIMARY KEY can be specified for a table.
d821 1
a821 1
[ CONSTRAINT <replaceable class="parameter">name</replaceable> ] REFERENCES <replaceable class="parameter">reftable</replaceable> [ ( <replaceable class="parameter">refcolumn</replaceable> ) ] 
d841 1
a841 1
       <term>CONSTRAINT <replaceable class="PARAMETER">name</replaceable></term>
d844 1
a844 1
	 An arbitrary name for the constraint.
d876 1
a876 1
         allows a some foreign key columns to be NULL while other parts
d1102 1
a1102 1
   Table CONSTRAINT Clause
d1106 1
a1106 1
[ CONSTRAINT name ] { PRIMARY KEY |  UNIQUE } ( <replaceable class="parameter">column</replaceable> [, ...] )
d1108 2
a1109 3
[ CONSTRAINT name ] FOREIGN KEY ( <replaceable class="parameter">column</replaceable> [, ...] ) 
                     REFERENCES <replaceable class="parameter">reftable</replaceable>
                      (<replaceable class="parameter">refcolumn</replaceable> [, ...] )
d1126 1
a1126 1
      <term>CONSTRAINT <replaceable class="parameter">name</replaceable></term>
d1129 1
a1129 1
	An arbitrary name given to an integrity constraint.
d1134 1
a1134 1
      <term><replaceable class="parameter">column</replaceable> [, ...]</term>
d1172 1
a1172 1
    more columns of a base table. The four variations of "Table
d1189 1
a1189 1
[ CONSTRAINT <replaceable class="parameter">name</replaceable> ] UNIQUE ( <replaceable class="parameter">column</replaceable> [, ...] )
d1196 1
a1196 1
      <term>CONSTRAINT <replaceable class="parameter">name</replaceable></term>
d1199 1
a1199 1
	An arbitrary name given to a constraint.
d1263 1
a1263 1
     Define a UNIQUE table constraint for the table distributors:
d1268 1
a1268 1
    UNIQUE(name)
d1281 1
a1281 1
[ CONSTRAINT <replaceable class="PARAMETER">name</replaceable> ] PRIMARY KEY ( <replaceable class="PARAMETER">column</replaceable> [, ...] ) 
d1290 1
a1290 1
       <term>CONSTRAINT <replaceable class="PARAMETER">name</replaceable></term>
d1293 1
a1293 1
	 An arbitrary name for the constraint.
d1298 1
a1298 1
       <term><replaceable class="PARAMETER">column</replaceable> [, ...]</term>
d1362 2
a1363 2
[ CONSTRAINT <replaceable class="parameter">name</replaceable> ] FOREIGN KEY ( <replaceable class="parameter">column</replaceable> [, ...] )
    REFERENCES <replaceable class="parameter">reftable</replaceable> [ ( <replaceable class="parameter">refcolumn</replaceable> [, ...] ) ] 
d1371 3
a1373 3
    The REFERENCES constraint specifies a rule that a column value is
    checked against the values of another column. REFERENCES can also be
    specified as part of a FOREIGN KEY table constraint.
d1381 1
a1381 1
       <term>CONSTRAINT <replaceable class="PARAMETER">name</replaceable></term>
d1384 1
a1384 1
	 An arbitrary name for the constraint.
d1389 1
a1389 1
       <term><replaceable class="PARAMETER">column</replaceable> [, ...]</term>
d1405 1
a1405 1
       <term><replaceable class="parameter">referenced column</replaceable> [, ...]</term>
d1408 1
a1408 1
         One or more column in the <replaceable class="parameter">reftable</replaceable>
d1765 1
a1765 1
    DEFAULT <replaceable class="parameter">value</replaceable> ] [ CONSTRAINT <replaceable class="parameter">column_constraint</replaceable> ] [, ...] )
d1772 2
a1773 2
    names a new table visible to other clients and defines the table's columns and
    constraints. 
d1778 4
a1781 13
    whenever COMMIT is executed. If the ON COMMIT clause is omitted, the
    default option, ON COMMIT DELETE ROWS, is assumed.
   </para>
   <para>
    To create a temporary table:

    <programlisting>
CREATE TEMPORARY TABLE actors (
    id         DECIMAL(3),
    name       VARCHAR(40),
    CONSTRAINT actor_id CHECK (id &lt; 150)
) ON COMMIT DELETE ROWS;
    </programlisting>
d1795 1
a1795 1
[ CONSTRAINT <replaceable>name</replaceable> ] UNIQUE ( <replaceable>column</replaceable> [, ...] )
d1805 1
a1805 1
[ CONSTRAINT <replaceable>name</replaceable> ] UNIQUE
d1818 3
a1820 2
	<productname>Postgres</productname> extension to SQL92 is
	included for symmetry with the NOT NULL clause. Since it is the
d1823 1
a1823 1
[ CONSTRAINT <replaceable>name</replaceable> ] NULL 
d1836 1
a1836 1
[ CONSTRAINT <replaceable>name</replaceable> ] NOT NULL 
d1882 1
a1882 1
     not necessarily dependent on one particular base table as
d1898 1
a1898 1
[ CONSTRAINT <replaceable>name</replaceable> ] CHECK <replaceable>constraint</replaceable> 
d1908 1
a1908 1
[ CONSTRAINT <replaceable>name</replaceable> ] { PRIMARY KEY ( <replaceable class="parameter">column</replaceable>, ... ) | FOREIGN KEY <replaceable>constraint</replaceable> | UNIQUE <replaceable>constraint</replaceable> | CHECK <replaceable>constraint</replaceable> }
d1918 1
a1918 1
[ CONSTRAINT <replaceable>name</replaceable> ] { NOT NULL | PRIMARY KEY | FOREIGN KEY <replaceable>constraint</replaceable> | UNIQUE | CHECK <replaceable>constraint</replaceable> }  
d1960 1
a1960 2
	 Check constraint only at the end of the transaction. This
	 is the default
d1968 1
a1968 1
	 Check constraint after each statement.
d1998 1
a1998 1
[ CONSTRAINT <replaceable>name</replaceable> ] CHECK ( VALUE <replaceable>condition</replaceable> ) 
d2007 1
a2007 1
[ CONSTRAINT <replaceable>name</replaceable> ] CHECK ( VALUE <replaceable>condition</replaceable> ) 
d2046 1
a2046 1
[ CONSTRAINT <replaceable>name</replaceable> ] PRIMARY KEY ( <replaceable>column</replaceable> [, ...] ) 
d2054 1
a2054 1
[ CONSTRAINT <replaceable>name</replaceable> ] PRIMARY KEY 
@


1.38
log
@Correct UNDER syntax.
@
text
@d2 1
a2 1
$Header: /home/projects/pgsql/cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v 1.37 2000/12/25 23:15:26 petere Exp $
d23 1
a23 1
   <date>2000-03-25</date>
d26 1
a26 3
CREATE [ TEMPORARY | TEMP ] TABLE <replaceable class="PARAMETER">table</replaceable> 
    [ UNDER <replaceable>inherited_table</replaceable> [, ...] ]
    (
d34 1
a34 1
    )
d133 1
a133 1
      <term>UNDER <replaceable class="PARAMETER">inherited_table</replaceable></term>
d136 1
a136 1
	The optional UNDER clause specifies a collection of table
d232 1
a232 1
   The optional UNDER
d2153 13
@


1.37
log
@Refine some things to create better looking man pages.
@
text
@d2 1
a2 1
$Header: /home/projects/pgsql/cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v 1.36 2000/10/08 13:22:24 petere Exp $
d26 3
a28 1
CREATE [ TEMPORARY | TEMP ] TABLE <replaceable class="PARAMETER">table</replaceable> (
d36 1
a36 1
    ) [ UNDER <replaceable>inherited_table</replaceable> [, ...] ]
d63 1
a63 1
	The name of a new class or table to be created.
d210 1
a210 1
   <command>CREATE TABLE</command> will enter a new class or table
d235 1
a235 1
   clause specifies a collection of class names from which this class
d238 1
a238 1
   allows the created class to inherit functions on classes above it in
d244 3
a246 3
   Each new table or class <replaceable class="PARAMETER">table</replaceable>
   is automatically created as a type.  Therefore, one or more instances
   from the class are automatically a type and can be used in 
a1834 10
  
  <refsect2 id="R2-SQL-CREATETABLE-3">
   <title>
    Notes
   </title>
   <para>
    CREATE TABLE/UNDER is defined by SQL3. Multiple inheritance is a 
     <productname>Postgres</productname> language extension.
   </para>
  </refsect2>
@


1.36
log
@markup repair
@
text
@d2 1
a2 1
$Header: /home/projects/pgsql/cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v 1.35 2000/10/05 19:48:17 momjian Exp $
d245 1
a245 1
   <xref linkend="sql-altertable-title" endterm="sql-altertable-title">
@


1.35
log
@Add proofreader's changes to docs.
Fix misspelling of disbursion to dispersion.
@
text
@d2 1
a2 1
$Header: /home/projects/pgsql/cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v 1.34 2000/08/24 23:36:29 tgl Exp $
d2052 6
a2059 6
     </variablelist>
     <para>  
     <term>SET CONSTRAINT</term> changes the foreign key constraint mode
	only for the current transaction.
     </para>
     <variablelist>
@


1.34
log
@Documentation updates to reflect TOAST and new-style fmgr.
@
text
@d2 1
a2 1
$Header: /home/projects/pgsql/cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v 1.33 2000/07/22 04:30:27 momjian Exp $
d126 1
a126 1
	are mutually exclusive.. See the table constraint clause for
d180 1
a180 1
	which occurs at runtime, if the table specified already exists
d699 1
a699 1
     details.).
d856 1
a856 1
	This occurs at run-time if one tries to insert a duplicate value into
d885 1
a885 1
     data integrity. (See CREATE INDEX statement)
d1160 1
a1160 1
     A value added to this column are matched against the values of the
d1423 2
a1424 2
     or more distinct columns of a table may contain only unique,
     (non duplicate), non-null values. The column definitions of
d1508 1
a1508 1
         allows a some foreign key columns to be NULL while other parts
d1699 1
a1699 1
     or more distinct columns of a table are related to a group
d1856 1
a1856 1
    In addition to the locally-visible temporary table, SQL92 also defines a
d1984 1
a1984 1
     An assertion is a special type of integrity constraint and share
d2055 4
a2058 4
    </para>
    <para>
     SET CONSTRAINT changes the foreign key constraint mode only for
     the current transaction.
@


1.33
log
@spell cleanups
@
text
@d2 1
a2 1
$Header: /home/projects/pgsql/cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v 1.32 2000/07/22 02:39:10 momjian Exp $
d251 3
a253 5
   A table can have no more than 1600 columns (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 table cannot have the same name as
   a system catalog table.
@


1.32
log
@Cleanups
@
text
@d2 1
a2 1
$Header: /home/projects/pgsql/cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v 1.31 2000/07/14 15:27:14 thomas Exp $
d1354 1
a1354 1
    did      DECIMAL(03),
d1740 1
a1740 1
     did      DECIMAL(03) PRIMARY KEY DEFAULT NEXTVAL('serial'),
d1765 1
a1765 1
    did       DECIMAL(03),
d1804 1
a1804 1
    code      CHAR(05),
d1806 1
a1806 1
    did       DECIMAL(03),
d1822 1
a1822 1
    did      DECIMAL(03),
d1830 1
a1830 1
    did      DECIMAL(03) PRIMARY KEY,
d1884 1
a1884 1
    id         DECIMAL(03),
@


1.31
log
@Add information on SET SESSION CHARACTERISTICS.
Fix references to pg_hba.conf(5) since that is no longer a man page.
Make minor repairs to "Compatibility" subsections.
@
text
@d2 1
a2 1
$Header: /home/projects/pgsql/cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v 1.30 2000/06/09 01:43:57 momjian Exp $
d224 1
a224 1
     As of Postgres version 6.0, consistent array dimensions within an
@


1.30
log
@Inheritance overhaul by  Chris Bitmead <chris@@bitmead.com>
@
text
@d2 1
a2 1
$Header: /usr/local/cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v 1.29 2000/05/02 20:02:03 thomas Exp $
d1852 1
a1852 1
  
@


1.29
log
@Fixups in content and markup for 7.0 release.
@
text
@d2 1
a2 1
$Header: /usr/local/cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v 1.28 2000/04/15 23:29:58 momjian Exp $
d34 1
a34 1
    ) [ INHERITS ( <replaceable>inherited_table</replaceable> [, ...] ) ]
d133 1
a133 1
      <term>INHERITS <replaceable class="PARAMETER">inherited_table</replaceable></term>
d136 1
a136 1
	The optional INHERITS clause specifies a collection of table
d232 1
a232 1
   The optional INHERITS
d1841 2
a1842 2
    CREATE TABLE/INHERITS is a <productname>Postgres</productname>
    language extension.
@


1.28
log
@SYstem user not implemented
@
text
@d2 1
a2 1
$Header: /usr/local/cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v 1.27 2000/04/14 22:53:10 momjian Exp $
d908 6
a913 7
[ CONSTRAINT <replaceable class="parameter">name</replaceable> ] REFERENCES 
<replaceable class="parameter">reftable</replaceable> [ ( <replaceable class="parameter">refcolumn</replaceable> ) ] 
[ MATCH <replaceable class="parameter">matchtype</replaceable> ]
[ ON DELETE <replaceable class="parameter">action</replaceable> ] 
[ ON UPDATE <replaceable class="parameter">action</replaceable> ]
[ [ NOT ] DEFERRABLE ] 
[ INITIALLY <replaceable class="parameter">checktime</replaceable> ]
d1450 7
a1456 8
[ CONSTRAINT <replaceable class="parameter">name</replaceable> ] 
FOREIGN KEY ( <replaceable class="parameter">column</replaceable> [, ...] ) REFERENCES 
<replaceable class="parameter">reftable</replaceable> [ ( <replaceable class="parameter">refcolumn</replaceable> [, ...] ) ] 
[ MATCH <replaceable class="parameter">matchtype</replaceable> ]
[ ON DELETE <replaceable class="parameter">action</replaceable> ] 
[ ON UPDATE <replaceable class="parameter">action</replaceable> ]
[ [ NOT ] DEFERRABLE ]
[ INITIALLY <replaceable class="parameter">checktime</replaceable> ]
d1902 1
a1902 1
[ CONSTRAINT name ] UNIQUE ( column [, ...] )
d1912 1
a1912 1
[ CONSTRAINT name ] UNIQUE
d1929 1
a1929 1
[ CONSTRAINT name ] NULL 
d1942 1
a1942 1
[ CONSTRAINT name ] NOT NULL 
d1966 1
a1966 3
     DEFAULT niladic USER function |
             niladic datetime function |
             NULL
d1993 1
a1993 1
CREATE ASSERTION name CHECK ( condition )
d2004 1
a2004 1
[ CONSTRAINT name ] CHECK constraint 
d2014 1
a2014 1
[ CONSTRAINT name ] { PRIMARY KEY ( <replaceable class="parameter">column</replaceable>, ... ) | FOREIGN KEY constraint | UNIQUE constraint | CHECK constraint }
d2024 1
a2024 1
[ CONSTRAINT name ] { NOT NULL | PRIMARY KEY | FOREIGN KEY constraint | UNIQUE | CHECK constraint }  
d2066 2
a2067 2
	     Check constraint only at the end of the transaction. This
	     is the default
d2075 1
a2075 1
	     Check constraint after each statement.
d2105 1
a2105 1
[ CONSTRAINT name ] CHECK ( VALUE condition ) 
d2114 1
a2114 1
[ CONSTRAINT name ] CHECK ( VALUE condition ) 
d2124 1
a2124 1
     [ CONSTRAINT name ] 
d2153 1
a2153 1
[ CONSTRAINT name ] PRIMARY KEY ( column [, ...] ) 
d2161 1
a2161 1
[ CONSTRAINT name ] PRIMARY KEY 
@


1.27
log
@update
@
text
@d2 1
a2 1
$Header: /usr/local/cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v 1.26 2000/04/14 22:23:02 momjian Exp $
d356 1
a356 1
	  <simpara>See CURRENT_USER function</simpara>
@


1.26
log
@MOre cleanup
@
text
@d2 1
a2 1
$Header: /usr/local/cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v 1.25 2000/04/14 22:16:01 momjian Exp $
d964 1
a964 1
         allows a single foreign key column to be NULL while other parts
d1512 1
a1512 1
         allows a single foreign key column to be NULL while other parts
@


1.25
log
@Update
@
text
@d2 1
a2 1
$Header: /usr/local/cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v 1.24 2000/04/14 22:13:24 momjian Exp $
d2063 2
a2064 3
     The constraint mode for every Constraint always has an initial
     default value which is set for that Constraint at the beginning
     of a transaction.
@


1.24
log
@update
@
text
@d2 1
a2 1
$Header: /usr/local/cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v 1.23 2000/04/14 21:44:21 momjian Exp $
d965 2
a966 2
         of the foreign key are not NULL. MATCH PARTIAL is not currently
         supported.
d1513 2
a1514 2
         of the foreign key are not NULL. MATCH PARTIAL is not currently
         supported.
@


1.23
log
@Updates create_function.sgml with fixes for new foreign keys
@
text
@d2 1
a2 1
$Header: /usr/local/cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v 1.22 2000/04/13 07:19:27 momjian Exp $
d960 7
a966 5
         The type of comparison to do between the table data. There are
         three types of matching, MATCH FULL, MATCH PARTIAL, and the
         unspecified match type used if no match type is specified.
         MATCH PARTIAL is not
         currently supported.
d1179 1
a1179 1
     FULL and an unspecified match type. In addition, the referenced
d1508 7
a1514 4
         The type of comparison to do between the table data. There are
         three types of matching, MATCH FULL, MATCH PARTIAL, and the
         unspecified match type used if no match type is specified.
         MATCH PARTIAL is not currently supported.
@


1.22
log
@No longer need to cast default non-cacheable functions.
@
text
@d2 1
a2 1
$Header: /usr/local/cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v 1.21 2000/04/12 04:40:03 thomas Exp $
d100 10
a109 9
	The optional column constraint clauses specify a list of integrity 
	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. Although <acronym>SQL92</acronym>
	requires the <replaceable class="PARAMETER">column_constraint_clause</replaceable>
	to refer to that column only, <productname>Postgres</productname>
	allows multiple columns
	to be referenced within a single column constraint.
	See the column constraint clause for more information.
d118 10
a127 10
	The optional table CONSTRAINT clause specifies a list of integrity 
	constraints which new or updated entries must satisfy for
	an insert or update operation to succeed. Each constraint
	must evaluate to a boolean expression. Multiple columns
	may be referenced within a single constraint.
	Only one PRIMARY KEY clause may be specified for a table;
	PRIMARY KEY <replaceable>column</replaceable>
	(a table constraint) and PRIMARY KEY (a column constraint) are
	mutually exclusive..
	See the table constraint clause for more information.
a143 7
	<note>
	 <title>Aside</title>
	 <para>
	  Inheritance of functions is done according
	  to the conventions of the Common Lisp Object System (CLOS).
	 </para>
	</note>
d224 1
a224 1
     As of Postgres version 6.0, consistant array dimensions within an
d350 1
a350 1
	  <simpara>not yet supported</simpara>
d356 1
a356 1
	  <simpara>not yet supported</simpara>
d499 3
a501 3
	enforced by the system and that other tables may rely on this column
	as a unique identifier for rows.
	See PRIMARY KEY for more information.
d526 6
a531 7
    The optional constraint
    clauses specify 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.  The use of PRIMARY KEY
    as a table constraint
    is mutually incompatible with PRIMARY KEY as a column constraint.
d546 3
a548 4
    A column constraint is an integrity constraint defined as part
    of a column definition, and logically becomes a table
    constraint as soon as it is created. The column
    constraints available are:
a557 8

   <note>
    <para>
     <productname>Postgres</productname> now
     (new for v7.0) supports
     REFERENCES integrity constraints.
    </para>
   </note>
d697 5
a701 5
     constraint.  Having more than one null value in a column without a
     NOT NULL constraint, does not violate a UNIQUE constraint.
     (This deviates from the <acronym>SQL92</acronym> definition, but
     is a more sensible convention. See the section on compatibility
     for more details.).
d814 2
a815 2
     within a column.
     The CHECK constraint is also allowed as a table constraint.
d819 2
a820 3
     refer to, one column of the table. <productname>Postgres</productname>
     does not have
     this restriction.
d869 5
a873 5
     The PRIMARY KEY column constraint specifies that a column of a table
     may contain only unique
     (non-duplicate), non-NULL values. The definition of
     the specified column does not have to include an explicit NOT NULL
     constraint to be included in a PRIMARY KEY constraint. 
d960 5
a964 3
         The type of comparison to do between the table data.  There are three
         types of matching, MATCH FULL, MATCH PARTIAL, and the unspecified match type
         used if no match type is specified.
d976 1
a976 1
           <term>CASCADE</term>
d979 1
a979 1
             Delete any rows referencing the deleted row.
d987 1
a987 1
             Disallow deletion of rows being referenced.
d992 1
a992 1
           <term>SET NULL</term>
d995 1
a995 1
             Set the referencing column values to NULL.
d1000 1
a1000 1
           <term>SET DEFAULT</term>
d1003 1
a1003 1
             Set the referencing column values to their default value.
d1008 1
a1008 1
           <term>NO ACTION</term>
d1011 1
a1011 1
             Do nothing.
d1023 4
a1026 3
	 The action to do 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 changed, no action is done.  There are the following actions.
d1029 1
a1029 1
           <term>CASCADE</term>
d1032 1
a1032 2
             Update the value of the referencing column to the new value of the
             referenced column.
d1040 1
a1040 1
             Disallow update of row being referenced.
d1045 1
a1045 1
           <term>SET NULL</term>
d1048 2
a1049 1
             Set the referencing column values to NULL.
d1054 1
a1054 1
           <term>SET DEFAULT</term>
d1057 1
a1057 1
             Set the referencing column values to their default value.
d1062 1
a1062 1
           <term>NO ACTION</term>
d1065 1
a1065 1
             Do nothing.
d1078 4
a1081 2
         Tells the trigger manager whether this constraint may be 
         deferred to the end of transaction.
a1091 1

d1097 1
a1097 1
	     Check this constraint at the end of the transaction.
a1100 1

d1105 1
a1105 1
	     Check this constraint after each statement.
d1156 3
a1158 3
     The REFERENCES column constraint specifies that a column of a
     table must only contain values which match against values
     in a referenced column of a referenced table.
d1161 4
a1164 5
     A value added to this column are matched against the
     values of the referenced table and referenced column using
     the given match type.
     In addition, when the referenced column data is changed,
     actions are run upon this column's matching data.
d1176 5
a1180 6
     Currently <productname>Postgres</productname> only supports
     MATCH FULL and an unspecified match type.
     In addition, the referenced columns are supposed to be
     the columns of a UNIQUE constraint in the referenced table,
     however <productname>Postgres</productname> does not
     enforce this.
a1267 8

   <note>
    <para>
     <productname>Postgres</productname> now
     supports FOREIGN KEY
     integrity constraints
    </para>
   </note>
d1333 5
a1337 4
     The UNIQUE constraint specifies a rule that a group of one or
     more distinct columns of a table may 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.
d1408 2
a1409 2
	    This occurs at run-time if one tries to insert a duplicate value into
	    a column subject to a PRIMARY KEY constraint.
d1455 1
a1455 1
[ [ NOT ] DEFERRABLE ] 
d1459 3
a1461 4
    The REFERENCES constraint specifies a rule that a column
    value is checked against the values of another column.
    REFERENCES can also be specified as part of
    a FOREIGN KEY table constraint.
d1506 4
a1509 3
         The type of comparison to do between the table data.  There are three
         types of matching, MATCH FULL, MATCH PARTIAL, and the unspecified match type
         used if no match type is specified. 
d1521 1
a1521 1
           <term>CASCADE</term>
d1524 1
a1524 1
             Delete any rows referencing the deleted row.
d1532 1
a1532 1
             Disallow deletion of rows being referenced.
d1537 1
a1537 1
           <term>SET NULL</term>
d1540 1
a1540 1
             Set the referencing column values to NULL.
d1545 1
a1545 1
           <term>SET DEFAULT</term>
d1548 1
a1548 1
             Set the referencing column values to their default value.
d1553 1
a1553 1
           <term>NO ACTION</term>
d1556 1
a1556 1
             Do nothing.
d1568 4
a1571 3
	 The action to do 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 changed, no action is done.  There are the following actions.
d1574 1
a1574 1
           <term>CASCADE</term>
d1577 1
a1577 2
             Update the value of the referencing column to the new value of the
             referenced column.
d1590 1
a1590 1
           <term>SET NULL</term>
d1593 2
a1594 1
             Set the referencing column values to NULL.
d1599 1
a1599 1
           <term>SET DEFAULT</term>
d1602 1
a1602 1
             Set the referencing column values to their default value.
d1607 1
a1607 1
           <term>NO ACTION</term>
d1610 1
a1610 1
             Do nothing.
d1622 4
a1625 2
         Tells the trigger manager whether this constraint may be 
         deferred to the end of transaction.
d1633 3
a1635 2
         <replaceable class="parameter">checktime</replaceable> has two possible values 
         which specify the default time to check the constraint.
d1638 1
a1638 1
           <term>DEFERRED</term>
d1641 1
a1641 1
	     Check this constraint at the end of the transaction.
d1646 1
a1646 1
           <term>IMMEDIATE</term>
d1649 1
a1649 1
	     Check this constraint after each statement.
d1703 3
a1705 2
     The FOREIGN KEY table constraint is similar to that for column constraints,
     with the additional capability of encompassing multiple columns.
d1871 4
a1874 4
    The optional ON COMMIT clause of CREATE TEMPORARY TABLE
    specifies whether or not the temporary table should be emptied of
    rows whenever COMMIT is executed. If the ON COMMIT clause is
    omitted, the default option, ON COMMIT DELETE ROWS, is assumed. 
d1921 4
a1924 4
	The NULL "constraint" (actually a non-constraint)
	is a <productname>Postgres</productname> extension to SQL92
	is included for symmetry with the NOT NULL clause. Since it is the default
	for any column, its presence is simply noise.
d1986 4
a1989 5
     the same namespace as other constraints.
     However, an assertion is not necessarily dependent on one
     particular base table as constraints are, so SQL-92 provides the
     CREATE ASSERTION statement as an alternate method for defining a
     constraint:
d2037 3
a2039 2
	 means that the Constraint must be checked for
	 violation of its rule after the execution of every SQL statement.
d2047 5
a2051 3
	 means that checking of the Constraint may be deferred
	 until some later time, but no later than the end of the current
	 transaction.
d2066 2
a2067 3
	 means that, as of the start of the transaction,
	 the Constraint must be checked for violation of its rule after the
	 execution of every SQL statement.
d2075 2
a2076 3
	 means that, as of the start of the transaction,
	 checking of the Constraint may be deferred until some later time,
	 but no later than the end of the current transaction.</para>
@


1.21
log
@Fix up markup to allow building.
Adjust two-word substitution parameters to be one word only to reduce
 possible ambiguity.
@
text
@d2 1
a2 1
$Header: /usr/local/cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v 1.20 2000/04/11 14:43:54 momjian Exp $
a395 15
   <para>
    In the current release (v7.0), <productname>Postgres</productname>
    evaluates all default expressions at the time the table is defined.
    Hence, functions which are "non-cacheable" such as
    <function>CURRENT_TIMESTAMP</function> may not produce the desired
    effect. For the particular case of date/time types, one can work
    around this behavior by using 
    <quote>DEFAULT TEXT 'now'</quote>
    instead of
    <quote>DEFAULT 'now'</quote>
    or
    <quote>DEFAULT CURRENT_TIMESTAMP</quote>.
    This forces <productname>Postgres</productname> to consider the constant a string
    type and then to convert the value to <type>timestamp</type> at runtime.
   </para>
@


1.20
log
@    Attached  is  are  diffs  for  CREATE/ALTER  table  doc  I've
    forgotten in my mailbox (sorry). Haven't tried to  apply  and
    since I don't have working sgml stuff cannot check.

Jan
@
text
@d2 1
a2 1
$Header: /usr/local/cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v 1.19 2000/04/08 02:44:55 momjian Exp $
d454 3
a456 3
     <replaceable class="parameter">referenced table</replaceable>
     (<replaceable class="parameter">referenced column</replaceable>)
     [ MATCH <replaceable class="parameter">match type</replaceable> ]
d460 1
a460 1
     [ INITIALLY <replaceable class="parameter"> check time </replaceable> ] }
d941 1
a941 1
<replaceable class="parameter">referenced table</replaceable> [ ( <replaceable class="parameter"> referenced column</replaceable> ) ] 
d946 1
a946 1
[ INITIALLY <replaceable class="parameter"> check time </replaceable> ]
d957 1
d968 1
d970 1
a970 1
       <term><replaceable class="parameter">referenced table</replaceable></term>
d977 1
d979 1
a979 1
       <term><replaceable class="parameter">referenced column</replaceable></term>
d982 1
a982 1
         The column in the <replaceable class="parameter">referenced table</replaceable>
d984 1
a984 1
         <replaceable class="parameter">referenced table</replaceable> is used.
d1102 1
d1112 1
d1114 1
a1114 1
       <term>INITIALLY <replaceable class="parameter"> check time </replaceable></term>
d1117 1
a1117 1
         <replaceable class="parameter">check time</replaceable> has two possible values 
d1119 1
d1123 5
a1127 3
           <para>
            Check this constraint at the end of the transaction.
           </para>
d1129 1
d1132 6
a1137 4
           <para>
            Check this constraint after each statement.
           </para>
          </varlistentry>
d1164 1
a1164 1
<replaceable class="parameter">table</replaceable> not found in <replaceable class="parameter">referenced table</replaceable>
d1207 1
a1207 1
     MATCH FULL and an unspecified MATCH type.
d1214 1
d1226 3
a1228 3
                     REFERENCES <replaceable class="parameter">referenced table</replaceable>
                      (<replaceable class="parameter">referenced column</replaceable> [, ...] )
                      [ MATCH <match type> ] 
d1232 1
a1232 1
                      [ INITIALLY <replaceable class="parameter"> check time </replaceable> ]
d1479 1
a1479 1
  <refsect2 id="R2-SQL-REFERENCES-1">
d1489 1
a1489 1
<replaceable class="parameter">referenced table</replaceable> [ ( <replaceable class="parameter">referenced column</replaceable> [, ...] ) ] 
d1494 1
a1494 1
[ INITIALLY <replaceable class="parameter"> check time </replaceable> ]
d1503 1
a1503 1
   <refsect3 id="R3-SQL-REFERENCES-1">
d1524 1
a1524 1
       <term><replaceable class="parameter">referenced table</replaceable></term>
d1535 1
a1535 1
         One or more column in the <replaceable class="parameter">referenced table</replaceable>
d1537 1
a1537 1
         <replaceable class="parameter">referenced table</replaceable> is used.
d1665 1
a1665 1
       <term>INITIALLY <replaceable class="parameter"> check time </replaceable></term>
d1668 1
a1668 1
         <replaceable class="parameter">check time</replaceable> has two possible values 
d1673 5
a1677 3
           <para>
            Check this constraint at the end of the transaction.
           </para>
d1681 5
a1685 3
           <para>
            Check this constraint after each statement.
           </para>
d1694 1
a1694 1
   <refsect3 id="R3-SQL-REFERENCES-2">
d1711 1
a1711 1
<replaceable class="parameter">table</replaceable> not found in <replaceable class="parameter">referenced table</replaceable>
@


1.19
log
@update
@
text
@d2 1
a2 1
$Header: /usr/local/cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v 1.18 2000/03/27 17:14:42 thomas Exp $
d453 9
a461 1
     class="parameter">constraint</replaceable> } [, ...]
d911 1
a911 1
   
d931 272
d1213 8
d1465 1
d1467 263
@


1.18
log
@Start updating for the v7.0 release.
Use "generic functions" for math and other routines.
Use SQL92 "type 'literal'" syntax rather than Postgres "'literal'::type".
@
text
@d2 1
a2 1
$Header: /usr/local/cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v 1.17 1999/07/22 15:09:08 thomas Exp $
d1004 1
a1004 1
     integrity constraints (new for release 7.0).
@


1.17
log
@Complete merge of all old man page information.
ecpg reference page still needs formatting.
@
text
@d2 1
a2 1
$Header$
d23 1
a23 1
   <date>1999-07-20</date>
a37 3
   <refsect2info>
    <date>1998-09-11</date>
   </refsect2info>
a157 3
   <refsect2info>
    <date>1998-09-11</date>
   </refsect2info>
a208 3
  <refsect1info>
   <date>1998-09-11</date>
  </refsect1info>
a265 3
  <refsect1info>
   <date>1998-09-11</date>
  </refsect1info>
a274 3
   <refsect2info>
    <date>1998-09-11</date>
   </refsect2info>
a310 3
   <refsect2info>
    <date>1998-09-11</date>
   </refsect2info>
a319 3
   <refsect2info>
    <date>1998-09-11</date>
   </refsect2info>
d397 1
a397 1
    In the current release (v6.5), <productname>Postgres</productname>
a412 3
   <refsect2info>
    <date>1998-09-11</date>
   </refsect2info>
a445 3
  <refsect1info>
   <date>1998-09-11</date>
  </refsect1info>
a457 3
   <refsect2info>
    <date>1998-09-11</date>
   </refsect2info>
a533 3
   <refsect2info>
    <date>1998-09-11</date>
   </refsect2info>
d571 3
a573 1
    </simplelist></para>
d576 3
a578 4
     <productname>Postgres</productname> does not yet 
     (at release 6.5) support
     REFERENCES integrity constraints. The parser
     accepts the REFERENCES syntax but ignores the clause.
a583 3
   <refsect2info>
    <date>1998-09-11</date>
   </refsect2info>
a597 3
    <refsect3info>
     <date>1998-09-11</date>
    </refsect3info>
a627 3
    <refsect3info>
     <date>1998-09-11</date>
    </refsect3info>
a635 3
    <refsect3info>
     <date>1998-09-11</date>
    </refsect3info>
a655 3
   <refsect2info>
    <date>1998-09-11</date>
   </refsect2info>
a768 3
   <refsect2info>
    <date>1998-09-11</date>
   </refsect2info>
a801 3
    <refsect3info>
     <date>1998-09-11</date>
    </refsect3info>
a849 3
   <refsect2info>
    <date>1998-09-11</date>
   </refsect2info>
a904 3
    <refsect3info>
     <date>1998-09-11</date>
    </refsect3info>
a925 3
  <refsect1info>
   <date>1998-09-11</date>
  </refsect1info>
a935 3
   <refsect2info>
    <date>1998-09-11</date>
   </refsect2info>
a972 3
   <refsect2info>
    <date>1998-09-11</date>
   </refsect2info>
a983 3
   <refsect2info>
    <date>1998-09-11</date>
   </refsect2info>
d999 1
d1002 3
a1004 6
     <productname>Postgres</productname> does not yet 
     (as of version 6.5) support FOREIGN KEY
     integrity constraints. The parser understands the FOREIGN KEY syntax,
     but only prints a notice and otherwise ignores the clause.
     Foreign keys may be partially emulated by triggers (See the CREATE TRIGGER
     statement).
a1009 3
   <refsect2info>
    <date>1998-09-11</date>
   </refsect2info>
a1100 3
   <refsect2info>
    <date>1998-09-11</date>
   </refsect2info>
a1298 3
   <refsect2info>
    <date>1998-09-11</date>
   </refsect2info>
a1315 3
   <refsect2info>
    <date>1998-09-11</date>
   </refsect2info>
a1353 3
    <refsect3info>
     <date>1998-09-11</date>
    </refsect3info>
a1381 3
    <refsect3info>
     <date>1998-12-24</date>
    </refsect3info>
a1396 3
    <refsect3info>
     <date>1998-09-11</date>
    </refsect3info>
a1418 3
    <REFSECT3INFO>
     <DATE>1998-09-11</DATE>
    </REFSECT3INFO>
a1435 3
    <refsect3info>
     <date>1998-09-11</date>
    </refsect3info>
a1549 3
    <refsect3info>
     <date>1998-09-11</date>
    </refsect3info>
a1608 3
    <refsect3info>
     <date>1998-09-11</date>
    </refsect3info>
@


1.16
log
@Fix markup for docbook2man man page generation.
No big deal; fixed lots of other markup at the same time.
Bigest change: make sure there is no whitespace
 in front of <term> contents.
This will probably help the other output types too.
@
text
@d1 5
d8 1
a8 1
  <refentrytitle>
d23 1
a23 1
   <date>1998-09-11</date>
d64 1
a64 1
	The name of a new table to be created.
d221 1
d223 2
a224 2
   <command>CREATE TABLE</command> will enter a new table into the current data
   base. The table will be "owned" by the user issuing the
d227 37
d278 1
a278 1
  <title>
d473 1
a473 1
  <title>
d492 1
d570 1
d572 11
a582 1
    A Constraint is a named rule: an SQL object which helps define
d586 1
d591 1
d597 1
@


1.15
log
@Minor updates for release.
Split reference pages for CREATE TABLE AS and SELECT INTO to allow psgml
 (the emacs parser) to handle parsing.
@
text
@d22 2
a23 4
    <replaceable class="PARAMETER">column</replaceable> <replaceable
    class="PARAMETER">type</replaceable>
    [ NULL | NOT NULL ] [ UNIQUE ] [ DEFAULT <replaceable
    class="PARAMETER">value</replaceable> ]
d41 6
a46 8
   
   <variablelist>
    <varlistentry>
     <term>
     TEMPORARY
     </term>
     <listitem>
      <para>
d51 42
a92 3
      </para>
     </listitem>
    </varlistentry>
d94 16
a109 65
    <varlistentry>
     <term>
      <replaceable class="PARAMETER">table</replaceable>
     </term>
     <listitem>
      <para>
       The name of a new table to be created.
      </para>
     </listitem>
    </varlistentry>
    
    <varlistentry>
     <term>
      <replaceable class="PARAMETER">column</replaceable>
     </term>
     <listitem>
      <para>
       The name of a column.
      </para>
     </listitem>
    </varlistentry>
    
    <varlistentry>
     <term>
      <replaceable class="PARAMETER">type</replaceable>
     </term>
     <listitem>
      <para>
       The type of the column. This may include array specifiers.
       Refer to the <citetitle>PostgreSQL User's Guide</citetitle> for
       further information about data types and arrays.
      </para>
     </listitem>
    </varlistentry>
    
    <varlistentry>
     <term>
     DEFAULT <replaceable class="PARAMETER">value</replaceable>
     </term>
     <listitem>
      <para>
       A default value for a column.
       See the DEFAULT clause for more information.
      </para>
     </listitem>
    </varlistentry>
    
    <varlistentry>
     <term>
      <replaceable>column_constraint_clause</replaceable>
     </term>
     <listitem>
      <para>
       The optional column constraint clauses specify a list of integrity 
       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. Although <acronym>SQL92</acronym>
requires the <replaceable class="PARAMETER">column_constraint_clause</replaceable>
 to refer to that column only, <productname>Postgres</productname>
 allows multiple columns
       to be referenced within a single column constraint.
       See the column constraint clause for more information.
      </para>
     </listitem>
    </varlistentry>
d111 17
a127 19
    <varlistentry>
     <term>
      <replaceable>table_constraint_clause</replaceable>
     </term>
     <listitem>
      <para>
       The optional table CONSTRAINT clause specifies a list of integrity 
       constraints which new or updated entries must satisfy for
       an insert or update operation to succeed. Each constraint
       must evaluate to a boolean expression. Multiple columns
       may be referenced within a single constraint.
       Only one PRIMARY KEY clause may be specified for a table;
       PRIMARY KEY <replaceable>column</replaceable>
       (a table constraint) and PRIMARY KEY (a column constraint) are
       mutually exclusive..
       See the table constraint clause for more information.
      </para>
     </listitem>
    </varlistentry>
d130 1
a130 3
      <term>
       INHERITS <replaceable class="PARAMETER">inherited_table</replaceable>
      </term>
d154 1
a154 1
  
d164 28
a191 28
       <variablelist>
	<varlistentry>
	 <term>
	  <returnvalue>CREATE</returnvalue>
	 </term>
	 <listitem>
	  <para>
	   Message returned if table is successfully created.
	  </para>
	 </listitem>
	</varlistentry>
	
	<varlistentry>
	 <term>
	  <returnvalue>ERROR</returnvalue>
	 </term>
	 <listitem>
	  <para>
	   Message returned if table creation failed.
	   This is usually accompanied by some descriptive text, such as:
	   <programlisting>
amcreate: "<replaceable class="parameter">table</replaceable>" relation already exists
	   </programlisting>
	   which occurs at runtime, if the table specified already exists
	   in the database.
	  </para>
	 </listitem>
	</varlistentry>
d193 8
a200 8
	<varlistentry>
	 <term>
	  <returnvalue>ERROR:  DEFAULT: type mismatched</returnvalue>
	 </term>
	 <listitem>
	  <para>
	   if data type of default value doesn't match the
	   column definition's data type.
d208 1
a208 1
 
d232 8
a239 8
   <refsect1info>
    <date>1998-09-11</date>
   </refsect1info>
   <title>
    DEFAULT Clause
   </title>
   <para>
    <synopsis>
d241 1
a241 1
    </synopsis>
d248 21
a268 8
   Inputs
  </title>
  <para>
       <variablelist>
	<varlistentry>
	 <term>
	 <replaceable class="parameter">value</replaceable>
	 </term>
d270 2
a271 16
	  <para>
	   The possible values for the default value expression are:
	   <itemizedlist>
	    <listitem>
	     <simpara>
	      a literal value
	     </simpara>
	    </listitem>
	    <listitem>
	     <simpara>
	      a user function
	     </simpara>
	    </listitem>
	    <listitem>
	     <simpara>
	      a niladic function
d290 1
d299 57
a355 22
   Description
  </title>
  <para>
       The DEFAULT clause assigns a default data value to a column
       (via a column definition in the CREATE TABLE statement). 
       The data type of a default value must match the column definition's
       data type.
      </para>
      <para>
       An INSERT operation that includes a column without a specified
       default value will assign the NULL value to the column
       if no explicit data value is provided for it.
       Default <replaceable class="parameter">literal</replaceable> means
       that the default is the specified constant value.
       Default <replaceable class="parameter">niladic-function</replaceable>
       or <replaceable class="parameter">user-function</replaceable> means
       that the default
       is the value of the specified function at the time of the INSERT.
      </para>
      <para>
       There are two types of niladic functions:
<variablelist>
d357 1
a357 1
	 <term>niladic USER</term>
d359 1
a359 20
	  <variablelist>
	   <varlistentry>
	    <term>CURRENT_USER / USER</term>
	    <listitem>
	     <simpara>See CURRENT_USER function</simpara>
	    </listitem>
	   </varlistentry>
	   <varlistentry>
	    <term>SESSION_USER</term>
	    <listitem>
	     <simpara>not yet supported</simpara>
	    </listitem>
	   </varlistentry>
	   <varlistentry>
	    <term>SYSTEM_USER</term>
	    <listitem>
	     <simpara>not yet supported</simpara>
	    </listitem>
	   </varlistentry>
	  </variablelist>
d363 1
a363 1
	 <term>niladic datetime</term>
d365 1
a365 20
	  <variablelist>
	   <varlistentry>
	    <term> CURRENT_DATE</term>
	    <listitem>
	     <simpara>See CURRENT_DATE function</simpara>
	    </listitem>
	   </varlistentry>
	   <varlistentry>
	    <term>CURRENT_TIME</term>
	    <listitem>
	     <simpara>See CURRENT_TIME function</simpara>
	    </listitem>
	   </varlistentry>
	   <varlistentry>
	    <term>CURRENT_TIMESTAMP</term>
	    <listitem>
	     <simpara>See CURRENT_TIMESTAMP function</simpara>
	    </listitem>
	   </varlistentry>
	  </variablelist>
d369 3
d374 14
a387 20
<para>
In the current release (v6.5), <productname>Postgres</productname>
evaluates all default expressions at the time the table is defined.
Hence, functions which are "non-cacheable" such as
 <function>CURRENT_TIMESTAMP</function> may not produce the desired
effect. For the particular case of date/time types, one can work
around this behavior by using 
<quote>
DEFAULT TEXT 'now'
</quote>
instead of
<quote>
DEFAULT 'now'
</quote>
or
<quote>
DEFAULT CURRENT_TIMESTAMP
</quote>.
This forces <productname>Postgres</productname> to consider the constant a string
type and then to convert the value to <type>timestamp</type> at runtime.
d395 1
a395 1
  Usage
d397 1
d399 5
a403 5
   To assign a constant value as the default for the
 columns <literal>did</literal> and <literal>number</literal>,
   and a string literal to the column <literal>did</literal>:
  
  <programlisting>
d409 1
a409 1
  </programlisting>
d412 5
a416 5
   To assign an existing sequence
 as the default for the column <literal>did</literal>,
   and a literal to the column <literal>name</literal>:
  
  <programlisting>
d421 1
a421 1
  </programlisting>
d424 7
a430 7
  </refsect1>
  
  <refsect1 id="R1-SQL-COLUMNCONSTRAINT-1">
   <refsect1info>
    <date>1998-09-11</date>
   </refsect1info>
   <title>
d432 2
a433 2
   </title>
   <para>
d449 43
a491 15
       <variablelist>
	<varlistentry>
	 <term>
	   <replaceable class="parameter">name</replaceable>
	 </term>
	 <listitem>
	  <para>
          An arbitrary name given to the integrity constraint. 
If <replaceable class="parameter">name</replaceable> is not specified,
 it is generated from the table and column names,
which should ensure uniqueness for
 <replaceable class="parameter">name</replaceable>.
	  </para>
	 </listitem>
	</varlistentry>
d493 11
a503 35
    <varlistentry>
     <term>
     NULL
     </term>
     <listitem>
      <para>
The column is allowed to contain NULL values. This is the default.
      </para>
     </listitem>
    </varlistentry>
    
    <varlistentry>
     <term>
     NOT NULL
     </term>
     <listitem>
      <para>
The column is not allowed to contain NULL values.
This is equivalent to the column constraint
 CHECK (<replaceable class="PARAMETER">column</replaceable> NOT NULL).
      </para>
     </listitem>
    </varlistentry>
    
    <varlistentry>
     <term>
     UNIQUE
     </term>
     <listitem>
      <para>
The column must have unique values. In <productname>Postgres</productname>
this is enforced by an implicit creation of a unique index on the table.
      </para>
     </listitem>
    </varlistentry>
d505 12
a516 26
    <varlistentry>
     <term>
     PRIMARY KEY
     </term>
     <listitem>
      <para>
       This column is a primary key, which implies that uniqueness is
enforced by the system and that other tables may rely on this column
as a unique identifier for rows.
       See PRIMARY KEY for more information.
      </para>
     </listitem>
    </varlistentry>
    
	<varlistentry>
	 <term>
	   <replaceable class="parameter">constraint</replaceable>
	 </term>
	 <listitem>
	  <para>
	   The definition of the constraint.
	  </para>
	 </listitem>
	</varlistentry>
       </variablelist>
    </para>
d582 22
a604 25
    <variablelist>
     <varlistentry>
      <term>
       <replaceable>status</replaceable>
      </term>
      <listitem>
       <para>
	<variablelist>
	 <varlistentry>
	  <term>
	   <returnvalue>ERROR:  ExecAppend: Fail to add null value in not
	    null attribute "<replaceable class="parameter">column</replaceable>".</returnvalue>
	  </term>
	  <listitem>
	   <para>
	    This error occurs at runtime if one tries to insert a null value
	    into a column which has a NOT NULL constraint.
	   </para>
	  </listitem>
	 </varlistentry>
	</variablelist>
       </para>
      </listitem>
     </varlistentry>
    </variablelist> 
d617 1
a617 1
     
d625 1
a625 1
    
d630 6
a635 6
  
    <programlisting>
     CREATE TABLE distributors (
     did      DECIMAL(3) CONSTRAINT no_null NOT NULL,
     name     VARCHAR(40) NOT NULL
     );
d640 1
a640 1
  
d655 1
d658 1
a658 3
       <term>
	CONSTRAINT <replaceable class="parameter">name</replaceable>
       </term>
d672 14
a685 16
    <variablelist>
     <varlistentry>
      <term>
<replaceable>status</replaceable>
      </term>
      <listitem>
       <para>
	<variablelist>
	 <varlistentry>
	  <term>
<returnvalue>ERROR: Cannot insert a duplicate key into a unique index.</returnvalue>
	  </term>
	  <listitem>
	   <para>
	    This error occurs at runtime if one tries to insert a
	    duplicate value into a column.
d696 1
a696 1
   
d699 1
a699 1
Description
d711 3
a713 3
(This deviates from the <acronym>SQL92</acronym> definition, but
is a more sensible convention. See the section on compatibility
for more details.).
d723 1
a723 1
 index for each UNIQUE constraint, to assure
d729 4
a732 4
  <refsect3 id="R3-SQL-UNIQUECLAUSE-3">
   <title>
Usage
</title>
d734 9
a742 9
  <para>
   Defines a UNIQUE column constraint for the table distributors.
   UNIQUE column constraints can only be defined on one column
   of the table:
  <programlisting>
   CREATE TABLE distributors (
        did      DECIMAL(3),
        name     VARCHAR(40) UNIQUE
        );
d744 3
a746 2
which is equivalent to the following specified as a table constraint:
  <programlisting>
d752 1
a752 1
  </programlisting>
d756 1
a756 1
  
d761 4
a764 4
<title>
The CHECK Constraint
</title>
  <synopsis>
d767 1
a767 1
  </synopsis>
d770 8
a777 9
   <para>
       <variablelist>
	<varlistentry>
	 <term>
	  <returnvalue><replaceable class="parameter">name</replaceable></returnvalue>
	 </term>
	 <listitem>
	  <para>
	   An arbitrary name given to a constraint.
d782 1
a782 3
       <term>
	<replaceable>condition</replaceable>
       </term>
d792 1
a792 1
   
d801 1
d804 1
a804 3
       <term>
	<replaceable>status</replaceable>
       </term>
d807 1
a807 1
	 
d810 3
a812 6
	   <term>
	    <returnvalue>
	     ERROR:  ExecAppend: rejected due to CHECK constraint
	     "<replaceable class="parameter">table_column</replaceable>".
	    </returnvalue>
	   </term>
d827 1
a827 1
   
d854 1
a854 1
   
d860 1
a860 3
       <term>
CONSTRAINT <replaceable class="PARAMETER">name</replaceable>
       </term>
d875 3
a877 3
      <term>
<returnvalue>ERROR: Cannot insert a duplicate key into a unique index.</returnvalue>
      </term>
d892 1
a892 1
 may contain only unique
d911 1
a911 1
 a unique index to assure
d918 3
a920 3
of equivalent indexes and unproductive additional runtime overhead.
However, <productname>Postgres</productname> does not specifically
disallow this.
d935 2
a936 3
    [ CONSTRAINT name ] { PRIMARY KEY |  UNIQUE } ( <replaceable
     class="parameter">column</replaceable> [, ...] )
    [ CONSTRAINT name ] CHECK ( <replaceable>constraint</replaceable> )
d946 1
a946 1
   
d948 1
d951 1
a951 3
      <term>
       CONSTRAINT <replaceable class="parameter">name</replaceable>
      </term>
d959 1
a959 3
      <term>
       <replaceable class="parameter">column</replaceable> [, ...]
      </term>
d968 1
a968 3
      <term>
       CHECK ( <replaceable class="parameter">constraint</replaceable> )
      </term>
d1033 1
a1033 2
     [ CONSTRAINT <replaceable class="parameter">name</replaceable> ]
     UNIQUE ( <replaceable class="parameter">column</replaceable> [, ...] )
d1040 1
a1040 3
      <term>
       CONSTRAINT <replaceable class="parameter">name</replaceable>
      </term>
d1048 1
a1048 3
      <term>
       <replaceable class="parameter">column</replaceable>
      </term>
d1063 1
a1063 3
       <term>
	<replaceable>status</replaceable>
       </term>
d1068 1
a1068 3
	   <term>
	    ERROR: Cannot insert a duplicate key into a unique index.
	   </term>
d1108 5
a1112 5
      CREATE TABLE distributors (
      did      DECIMAL(03),
      name     VARCHAR(40),
      UNIQUE(name)
      );
d1127 1
a1127 2
     [ CONSTRAINT <replaceable class="PARAMETER">name</replaceable> ]
     PRIMARY KEY ( <replaceable class="PARAMETER">column</replaceable> [, ...] ) 
d1133 1
d1136 1
a1136 3
       <term>
	CONSTRAINT <returnvalue><replaceable class="PARAMETER">name</replaceable></returnvalue>
       </term>
d1144 1
a1144 3
       <term>
	<replaceable class="PARAMETER">column</replaceable> [, ...]
       </term>
d1159 1
a1159 3
      <term>
       <replaceable>status</replaceable>
      </term>
d1187 3
a1189 1
     
d1198 1
a1198 1
   
d1200 1
a1200 1
  
d1208 19
a1226 1
   Create table films and table distributors
a1227 10
  <programlisting>
   CREATE TABLE films (
          code      CHARACTER(5) CONSTRAINT firstkey PRIMARY KEY,
          title     CHARACTER VARYING(40) NOT NULL,
          did       DECIMAL(3) NOT NULL,
          date_prod DATE,
          kind      CHAR(10),
          len       INTERVAL HOUR TO MINUTE
          );
  </programlisting>
d1229 2
a1230 6
  <programlisting>
   CREATE TABLE distributors (
          did      DECIMAL(03) PRIMARY KEY DEFAULT NEXTVAL('serial'),
          name     VARCHAR(40) NOT NULL CHECK (name &lt;&gt; '')
          );
  </programlisting>
d1232 1
a1232 4
  <para>
   Create a table with a 2-dimensional array
  </para>
  <programlisting>
d1236 3
a1238 2
  </programlisting>
   
d1242 13
a1254 1
   columns of the table
a1255 11
  <programlisting>
   CREATE TABLE films (
       code      CHAR(5),
       title     VARCHAR(40),
       did       DECIMAL(03),
       date_prod DATE,
       kind      CHAR(10),
       len       INTERVAL HOUR TO MINUTE,
       CONSTRAINT production UNIQUE(date_prod)
       );
  </programlisting>
d1258 8
a1265 1
   Define a CHECK column constraint.
d1267 1
a1267 7
  <programlisting>
   CREATE TABLE distributors (
        did      DECIMAL(3) CHECK (did > 100),
        name     VARCHAR(40)
        );
  </programlisting>
  
d1269 9
a1277 1
   Define a CHECK table constraint
d1279 1
a1279 8
  <programlisting>
   CREATE TABLE distributors (
        did      DECIMAL(3),
        name     VARCHAR(40)
        CONSTRAINT con1 CHECK (did > 100 AND name > '')
        );
  </programlisting>
    
d1283 13
a1295 1
   columns of the table
d1297 1
a1297 12
  <programlisting>
   CREATE TABLE films (
       code      CHAR(05),
       title     VARCHAR(40),
       did       DECIMAL(03),
       date_prod DATE,
       kind      CHAR(10),
       len       INTERVAL HOUR TO MINUTE,
       CONSTRAINT code_title PRIMARY KEY(code,title)
       );
  </programlisting>
  
d1301 16
a1316 1
   of the table (the following two examples are equivalent)
a1317 12
  <programlisting>
   CREATE TABLE distributors (
        did      DECIMAL(03),
        name     CHAR VARYING(40),
        PRIMARY KEY(did)
        ); 

   CREATE TABLE distributors (
        did      DECIMAL(03) PRIMARY KEY,
        name     VARCHAR(40)
        );
  </programlisting>
d1347 3
a1349 3
    In addition to the normal CREATE TABLE, SQL92 also defines a
    CREATE TEMPORARY TABLE statement:
   </para>
d1351 3
a1353 4
   CREATE [ {GLOBAL | LOCAL} ] TEMPORARY TABLE table (
        column type [DEFAULT value] [CONSTRAINT column_constraint] [, ...] )
        [CONSTRAINT table_constraint ]
        [ ON COMMIT {DELETE | PRESERVE} ROWS ] 
d1355 2
d1358 2
a1359 2
    For temporary tables, the CREATE TEMPORARY TABLE statement
    names a new table and defines the table's columns and
d1370 8
d1379 1
a1379 19
   <programlisting>
      CREATE TEMPORARY TABLE actors (
             id      DECIMAL(03),
             name    VARCHAR(40),
             CONSTRAINT actor_id CHECK (id &lt; 150)
             ) ON COMMIT DELETE ROWS
   </programlisting> 
   <para>
    Temporary tables are not currently available
    in <productname>Postgres</productname>.
    <tip>
     <para>
      In the current release of <productname>Postgres</productname>
      (v6.5), to create a temporary
      table you must create and drop the table by explicit commands.
     </para>
    </tip>
    </para>
    
d1391 7
a1397 1
     Table Constraint definition
d1399 6
a1404 3
    <synopsis>
      [ CONSTRAINT name ]
      UNIQUE ( column [, ...] )
d1407 1
a1407 3
    </synopsis>
    <para>
     Column Constraint definition
a1408 6
    <synopsis>
      [ CONSTRAINT name ]
      UNIQUE
      [ {INITIALLY DEFERRED | INITIALLY IMMEDIATE} ]
      [ [ NOT ] DEFERRABLE ]
    </synopsis>
d1423 4
a1426 4
    <synopsis>
     [ CONSTRAINT name ] NULL 
    </synopsis>
</para>
d1439 5
a1444 5
    <synopsis>
     [ CONSTRAINT name ] NOT NULL 
     [ {INITIALLY DEFERRED | INITIALLY IMMEDIATE} ]
     [ [ NOT ] DEFERRABLE ]
    </synopsis>
d1473 1
a1473 1
   
d1500 1
a1500 1
     CREATE ASSERTION name CHECK ( condition )
d1509 6
d1516 1
a1516 6
    <synopsis>
      [ CONSTRAINT name ] 
          CHECK constraint 
          [ {INITIALLY DEFERRED | INITIALLY IMMEDIATE} ]
          [ [ NOT ] DEFERRABLE ]
    </synopsis>
d1519 6
d1526 1
a1526 8
    <synopsis>
      [ CONSTRAINT name ] 
        { PRIMARY KEY constraint | 
          FOREIGN KEY constraint | 
          UNIQUE constraint | 
          CHECK constraint }
          [ {INITIALLY DEFERRED | INITIALLY IMMEDIATE} ]
          [ [ NOT ] DEFERRABLE ]</synopsis>
d1529 6
d1536 1
a1536 10
    <synopsis>
     [ CONSTRAINT name ] 
        { NOT NULL constraint |
          PRIMARY KEY constraint | 
          FOREIGN KEY constraint | 
          UNIQUE constraint | 
          CHECK constraint }  
          [ {INITIALLY DEFERRED | INITIALLY IMMEDIATE} ]
          [ [ NOT ] DEFERRABLE ]
    </synopsis>
d1614 2
a1615 4
    </para>
    <synopsis>
     [ CONSTRAINT name ] 
      CHECK ( VALUE condition ) 
d1618 3
a1620 1
    </synopsis>
a1622 1
    </para>
d1624 1
a1624 2
      [ CONSTRAINT name ] 
      CHECK ( VALUE condition ) 
d1628 1
d1630 1
a1630 1
    <para>
d1644 2
a1645 2
     CREATE DOMAIN duration AS SMALLINT 
        CONSTRAINT minutes CHECK (VALUE IN (90,120,180,240)); 
d1647 3
a1649 3
     ALTER DOMAIN cities 
        ADD CONSTRAINT new_city CHECK (VALUE LIKE 'L%');
    </programlisting>
d1652 1
a1652 2
   
   
d1665 5
a1670 6
    <synopsis>
      [ CONSTRAINT name ] 
      PRIMARY KEY ( column [, ...] ) 
      [ {INITIALLY DEFERRED | INITIALLY IMMEDIATE} ]
      [ [ NOT ] DEFERRABLE ]
    </synopsis>
d1673 5
a1678 6
    <synopsis>
      [ CONSTRAINT name ] 
      PRIMARY KEY 
      [ {INITIALLY DEFERRED | INITIALLY IMMEDIATE} ]
      [ [ NOT ] DEFERRABLE ]
    </synopsis>
@


1.14
log
@Fix markup to include all closing tags.
Required by newest versions of DocBook and style sheets.
@
text
@d1 3
a3 3
<REFENTRY ID="SQL-CREATETABLE">
 <REFMETA>
  <REFENTRYTITLE>
d5 5
a9 5
  </REFENTRYTITLE>
  <REFMISCINFO>SQL - Language Statements</REFMISCINFO>
 </REFMETA>
 <REFNAMEDIV>
  <REFNAME>
d11 2
a12 2
  </REFNAME>
  <REFPURPOSE>
d14 1
a14 1
  </REFPURPOSE>
d16 11
a26 9
 <REFSYNOPSISDIV>
  <REFSYNOPSISDIVINFO>
   <DATE>1998-09-11</DATE>
  </REFSYNOPSISDIVINFO>
  <SYNOPSIS>
CREATE [ TEMP ] TABLE <REPLACEABLE CLASS="PARAMETER">table</REPLACEABLE> (
    <REPLACEABLE CLASS="PARAMETER">column</REPLACEABLE> <REPLACEABLE CLASS="PARAMETER">type</REPLACEABLE>
    [ NULL | NOT NULL ] [ UNIQUE ] [ DEFAULT <REPLACEABLE CLASS="PARAMETER">value</REPLACEABLE> ]
    [<REPLACEABLE>column_constraint_clause</REPLACEABLE> | PRIMARY KEY } [ ... ] ]
d28 5
a32 5
    [, PRIMARY KEY ( <REPLACEABLE CLASS="PARAMETER">column</REPLACEABLE> [, ...] ) ]
    [, CHECK ( <REPLACEABLE CLASS="PARAMETER">condition</REPLACEABLE> ) ]
    [, <REPLACEABLE>table_constraint_clause</REPLACEABLE> ]
    ) [ INHERITS ( <REPLACEABLE>inherited_table</REPLACEABLE> [, ...] ) ]
  </SYNOPSIS>
d34 5
a38 5
  <REFSECT2 ID="R2-SQL-CREATETABLE-1">
   <REFSECT2INFO>
    <DATE>1998-09-11</DATE>
   </REFSECT2INFO>
   <TITLE>
d40 1
a40 1
   </TITLE>
d42 1
a42 1
   <PARA>
d44 7
a50 7
   <VARIABLELIST>
    <VARLISTENTRY>
     <TERM>
     TEMP
     </TERM>
     <LISTITEM>
      <PARA>
d55 10
a64 10
      </PARA>
     </LISTITEM>
    </VARLISTENTRY>

    <VARLISTENTRY>
     <TERM>
      <REPLACEABLE CLASS="PARAMETER">table</REPLACEABLE>
     </TERM>
     <LISTITEM>
      <PARA>
d66 3
a68 3
      </PARA>
     </LISTITEM>
    </VARLISTENTRY>
d70 6
a75 6
    <VARLISTENTRY>
     <TERM>
      <REPLACEABLE CLASS="PARAMETER">column</REPLACEABLE>
     </TERM>
     <LISTITEM>
      <PARA>
d77 3
a79 3
      </PARA>
     </LISTITEM>
    </VARLISTENTRY>
d81 6
a86 6
    <VARLISTENTRY>
     <TERM>
      <REPLACEABLE CLASS="PARAMETER">type</REPLACEABLE>
     </TERM>
     <LISTITEM>
      <PARA>
d90 3
a92 3
      </PARA>
     </LISTITEM>
    </VARLISTENTRY>
d94 6
a99 6
    <VARLISTENTRY>
     <TERM>
     DEFAULT <REPLACEABLE CLASS="PARAMETER">value</REPLACEABLE>
     </TERM>
     <LISTITEM>
      <PARA>
d102 3
a104 3
      </PARA>
     </LISTITEM>
    </VARLISTENTRY>
d106 6
a111 6
    <VARLISTENTRY>
     <TERM>
      <REPLACEABLE>column_constraint_clause</REPLACEABLE>
     </TERM>
     <LISTITEM>
      <PARA>
d116 2
a117 2
requires the <REPLACEABLE CLASS="PARAMETER">column_constraint_clause</REPLACEABLE>
 to refer to that column only, <ProductName>Postgres</ProductName>
d121 10
a130 10
      </PARA>
     </LISTITEM>
    </VARLISTENTRY>

    <VARLISTENTRY>
     <TERM>
      <REPLACEABLE>table_constraint_clause</REPLACEABLE>
     </TERM>
     <LISTITEM>
      <PARA>
d137 1
a137 1
       PRIMARY KEY <REPLACEABLE>column</REPLACEABLE>
d141 10
a150 10
      </PARA>
     </LISTITEM>
    </VARLISTENTRY>

     <VARLISTENTRY>
      <TERM>
       INHERITS <REPLACEABLE CLASS="PARAMETER">inherited_table</REPLACEABLE>
      </TERM>
      <LISTITEM>
       <PARA>
d166 4
a169 4
       </PARA>
      </LISTITEM>
     </VARLISTENTRY>
    </VARIABLELIST>
d171 1
a171 1
  </REFSECT2>
d173 5
a177 5
  <REFSECT2 ID="R2-SQL-CREATETABLE-2">
   <REFSECT2INFO>
    <DATE>1998-09-11</DATE>
   </REFSECT2INFO>
   <TITLE>
d179 2
a180 2
   </TITLE>
   <PARA>
d182 7
a188 7
       <VARIABLELIST>
	<VARLISTENTRY>
	 <TERM>
	  <ReturnValue>CREATE</ReturnValue>
	 </TERM>
	 <LISTITEM>
	  <PARA>
d190 3
a192 3
	  </PARA>
	 </LISTITEM>
	</VARLISTENTRY>
d194 6
a199 6
	<VARLISTENTRY>
	 <TERM>
	  <ReturnValue>ERROR</ReturnValue>
	 </TERM>
	 <LISTITEM>
	  <PARA>
d202 1
a202 1
	   <ProgramListing>
d204 1
a204 1
	   </ProgramListing>
d207 10
a216 10
	  </PARA>
	 </LISTITEM>
	</VARLISTENTRY>

	<VARLISTENTRY>
	 <TERM>
	  <ReturnValue>ERROR:  DEFAULT: type mismatched</ReturnValue>
	 </TERM>
	 <LISTITEM>
	  <PARA>
d222 1
a222 1
    </VARIABLELIST>
d224 2
a225 2
  </REFSECT2>
 </REFSYNOPSISDIV>
d227 5
a231 5
 <REFSECT1 ID="R1-SQL-CREATETABLE-1">
  <REFSECT1INFO>
   <DATE>1998-09-11</DATE>
  </REFSECT1INFO>
  <TITLE>
d233 2
a234 2
  </TITLE>
  <PARA>
d239 1
a239 1
  <PARA>
d246 1
a246 1
  </PARA>
d249 5
a253 5
 <REFSECT1 ID="R1-SQL-DEFAULTCLAUSE-1">
   <REFSECT1INFO>
    <DATE>1998-09-11</DATE>
   </REFSECT1INFO>
   <TITLE>
d255 5
a259 5
   </TITLE>
   <PARA>
    <SYNOPSIS>
DEFAULT <REPLACEABLE CLASS="PARAMETER">value</REPLACEABLE>
    </SYNOPSIS>
d261 5
a265 5
  <REFSECT2 ID="R2-SQL-DEFAULTCLAUSE-1">
   <REFSECT2INFO>
    <DATE>1998-09-11</DATE>
   </REFSECT2INFO>
   <TITLE>
d267 5
a271 5
  </TITLE>
  <PARA>
       <VARIABLELIST>
	<VARLISTENTRY>
	 <TERM>
d273 3
a275 3
	 </TERM>
	 <LISTITEM>
	  <PARA>
d296 1
a296 1
     </VARLISTENTRY>	
d301 5
a305 5
  <REFSECT2 ID="R2-SQL-DEFAULTCLAUSE-2">
   <REFSECT2INFO>
    <DATE>1998-09-11</DATE>
   </REFSECT2INFO>
   <TITLE>
d307 1
a307 1
   </TITLE>
d312 5
a316 5
  <REFSECT2 ID="R2-SQL-DEFAULTCLAUSE-3">
   <REFSECT2INFO>
    <DATE>1998-09-11</DATE>
   </REFSECT2INFO>
   <TITLE>
d318 2
a319 2
  </TITLE>
  <PARA>
d324 2
a325 2
      </PARA>
      <PARA>
d335 2
a336 2
      </PARA>
      <PARA>
d393 1
a393 1
In the current release (v6.4), <productname>Postgres</productname>
d414 5
a418 5
  <REFSECT2 ID="R2-SQL-DEFAULTCLAUSE-4">
   <REFSECT2INFO>
    <DATE>1998-09-11</DATE>
   </REFSECT2INFO>
   <TITLE>
d420 2
a421 2
   </TITLE>
   <PARA>
d426 1
a426 1
  <ProgramListing>
d432 1
a432 1
  </ProgramListing>
d434 1
a434 1
   <PARA>
d439 1
a439 1
  <ProgramListing>
d444 1
a444 1
  </ProgramListing>
d447 1
a447 1
  </REFSECT1>
d449 5
a453 5
  <REFSECT1 ID="R1-SQL-COLUMNCONSTRAINT-1">
   <REFSECT1INFO>
    <DATE>1998-09-11</DATE>
   </REFSECT1INFO>
   <TITLE>
d455 1
a455 1
   </TITLE>
d457 5
a461 3
   <SYNOPSIS>
[ CONSTRAINT <replaceable class="parameter">name</replaceable> ] { [ NULL | NOT NULL ] | UNIQUE | PRIMARY KEY | CHECK <replaceable class="parameter">constraint</replaceable> } [, ...]
   </SYNOPSIS>
d464 5
a468 5
  <REFSECT2 ID="R2-SQL-COLUMNCONSTRAINT-1">
   <REFSECT2INFO>
    <DATE>1998-09-11</DATE>
   </REFSECT2INFO>
   <TITLE>
d470 5
a474 5
   </TITLE>
   <PARA>
       <VARIABLELIST>
	<VARLISTENTRY>
	 <TERM>
d476 3
a478 3
	 </TERM>
	 <LISTITEM>
	  <PARA>
d484 3
a486 3
	  </PARA>
	 </LISTITEM>
	</VARLISTENTRY>
d488 2
a489 2
    <VARLISTENTRY>
     <TERM>
d491 3
a493 3
     </TERM>
     <LISTITEM>
      <PARA>
d495 3
a497 3
      </PARA>
     </LISTITEM>
    </VARLISTENTRY>
d499 2
a500 2
    <VARLISTENTRY>
     <TERM>
d502 3
a504 3
     </TERM>
     <LISTITEM>
      <PARA>
d507 4
a510 4
 CHECK (<REPLACEABLE CLASS="PARAMETER">column</REPLACEABLE> NOT NULL).
      </PARA>
     </LISTITEM>
    </VARLISTENTRY>
d512 2
a513 2
    <VARLISTENTRY>
     <TERM>
d515 4
a518 4
     </TERM>
     <LISTITEM>
      <PARA>
The column must have unique values. In <ProductName>Postgres</ProductName>
d520 3
a522 3
      </PARA>
     </LISTITEM>
    </VARLISTENTRY>
d524 2
a525 2
    <VARLISTENTRY>
     <TERM>
d527 3
a529 3
     </TERM>
     <LISTITEM>
      <PARA>
d534 3
a536 3
      </PARA>
     </LISTITEM>
    </VARLISTENTRY>
d538 2
a539 2
	<VARLISTENTRY>
	 <TERM>
d541 3
a543 3
	 </TERM>
	 <LISTITEM>
	  <PARA>
d545 4
a548 4
	  </PARA>
	 </LISTITEM>
	</VARLISTENTRY>
       </VARIABLELIST>
d552 5
a556 5
  <REFSECT2 ID="R2-SQL-COLUMNCONSTRAINT-2">
   <REFSECT2INFO>
    <DATE>1998-09-11</DATE>
   </REFSECT2INFO>
   <TITLE>
d558 1
a558 1
   </TITLE>
d583 1
a583 1
(at release 6.4) support
d585 1
a585 1
accepts the REFERENCES syntax but ignores the clause.
d590 5
a594 5
  <REFSECT2 ID="R2-SQL-NOTNULL-1">
   <REFSECT2INFO>
    <DATE>1998-09-11</DATE>
   </REFSECT2INFO>
   <TITLE>
d596 2
a597 2
   </TITLE>
   <SYNOPSIS>
d599 2
a600 2
   </SYNOPSIS>
   <PARA>
d603 3
a605 5
   </PARA>
   <PARA>
    The NOT NULL constraint is a column constraint only, and not allowed
as a table constraint.
   </PARA>
d607 5
a611 5
   <REFSECT3 ID="R3-SQL-NOTNULL-1">
    <REFSECT3INFO>
     <DATE>1998-09-11</DATE>
    </REFSECT3INFO>
    <TITLE>
d613 6
a618 6
    </TITLE>
    <PARA>
    </PARA>
    <VARIABLELIST>
     <VARLISTENTRY>
      <TERM>
d620 11
a630 11
      </TERM>
      <LISTITEM>
       <PARA>
	<VARIABLELIST>
	 <VARLISTENTRY>
	  <TERM>
	   <ReturnValue>ERROR:  ExecAppend: Fail to add null value in not
	    null attribute "<replaceable class="parameter">column</replaceable>".</ReturnValue>
	  </TERM>
	  <LISTITEM>
	   <PARA>
d633 3
a635 3
	   </PARA>
	  </LISTITEM>
	 </VARLISTENTRY>
d638 3
a640 3
      </LISTITEM>
     </VARLISTENTRY>
    </VARIABLELIST> 
d643 5
a647 5
   <REFSECT3 ID="R3-SQL-NOTNULL-2">
    <REFSECT3INFO>
     <DATE>1998-09-11</DATE>
    </REFSECT3INFO>
    <TITLE>
d654 5
a658 5
   <REFSECT3 ID="R3-SQL-NOTNULL-3">
    <REFSECT3INFO>
     <DATE>1998-09-11</DATE>
    </REFSECT3INFO>
    <TITLE>
d662 1
a662 1
    <PARA>
d667 1
a667 1
    <ProgramListing>
d672 1
a672 1
     </ProgramListing>
d677 5
a681 5
  <REFSECT2 ID="R2-SQL-UNIQUECLAUSE-1">
   <REFSECT2INFO>
    <DATE>1998-09-11</DATE>
   </REFSECT2INFO>
   <TITLE>
d683 1
a683 1
   </TITLE>
d686 1
a686 1
   </SYNOPSIS>
d708 4
a711 4
    <PARA>
    <VARIABLELIST>
     <VARLISTENTRY>
      <TERM>
d713 6
a718 6
      </TERM>
      <LISTITEM>
       <PARA>
	<VARIABLELIST>
	 <VARLISTENTRY>
	  <TERM>
d741 1
a741 1
    <PARA>
d753 2
a754 2
    </PARA>
    <PARA>
d758 3
a760 3
    </PARA>
    <Note>
     <Para>
d764 2
a765 2
     </Para>
    </Note>
d768 2
a769 2
  <REFSECT3 ID="R3-SQL-UNIQUECLAUSE-3">
   <TITLE>
d773 1
a773 1
  <PARA>
d777 1
a777 1
  <ProgramListing>
d782 1
a782 1
  </ProgramListing>
d784 1
a784 1
  <ProgramListing>
d790 1
a790 1
  </ProgramListing>
d795 4
a798 4
  <REFSECT2 ID="R2-SQL-CHECK-1">
   <REFSECT2INFO>
    <DATE>1998-09-11</DATE>
   </REFSECT2INFO>
d802 4
a805 3
  <SYNOPSIS>
[ CONSTRAINT <replaceable class="parameter">name</replaceable> ] CHECK ( <replaceable>condition</replaceable> [, ...] ) 
  </SYNOPSIS>
d808 8
a815 8
   <PARA>
       <VARIABLELIST>
	<VARLISTENTRY>
	 <TERM>
	  <ReturnValue><replaceable class="parameter">name</replaceable></ReturnValue>
	 </TERM>
	 <LISTITEM>
	  <PARA>
d817 5
a821 5
	</PARA>
       </LISTITEM>
      </VARLISTENTRY>
      <VARLISTENTRY>
       <TERM>
d823 3
a825 3
       </TERM>
       <LISTITEM>
	<PARA>
d827 3
a829 3
	</PARA>
       </LISTITEM>
      </VARLISTENTRY>
d832 1
a832 1
   </REFSECT3>
d834 5
a838 5
   <REFSECT3 ID="R3-SQL-CHECK-2">
    <REFSECT3INFO>
     <DATE>1998-09-11</DATE>
    </REFSECT3INFO>
    <TITLE>
d840 5
a844 5
    </TITLE>
    <PARA>
     <VARIABLELIST>
      <VARLISTENTRY>
       <TERM>
d846 3
a848 3
       </TERM>
       <LISTITEM>
	<PARA>
d850 4
a853 4
	 <VARIABLELIST>
	  <VARLISTENTRY>
	   <TERM>
	    <ReturnValue>
d856 4
a859 4
	    </ReturnValue>
	   </TERM>
	   <LISTITEM>
	    <PARA>
d862 3
a864 3
	    </PARA>
	   </LISTITEM>
	  </VARLISTENTRY>
d867 2
a868 2
       </LISTITEM>
      </VARLISTENTRY>
d871 1
a871 1
   </REFSECT3>
d879 2
a880 2
    </PARA>
    <PARA>
d885 1
a885 1
    </PARA>
d887 1
a887 1
  </REFSECT2>
d889 5
a893 5
  <REFSECT2 ID="R2-SQL-PRIMARYKEY-1">
   <REFSECT2INFO>
    <DATE>1998-09-11</DATE>
   </REFSECT2INFO>
   <TITLE>
d895 4
a898 4
   </TITLE>
   <SYNOPSIS>
[ CONSTRAINT <REPLACEABLE CLASS="PARAMETER">name</REPLACEABLE> ] PRIMARY KEY 
   </SYNOPSIS>
d902 8
a909 8
    <PARA>
     <VARIABLELIST>
      <VARLISTENTRY>
       <TERM>
CONSTRAINT <REPLACEABLE CLASS="PARAMETER">name</REPLACEABLE>
       </TERM>
       <LISTITEM>
	<PARA>
d911 4
a914 4
	</PARA>
       </LISTITEM>
      </VARLISTENTRY>
     </VARIABLELIST>
d929 1
a929 1
       </PARA>
d937 1
a937 1
    <PARA>
d943 2
a944 2
    </PARA>
    <PARA>
d946 2
a947 2
    </PARA>
   </REFSECT3>
d949 5
a953 5
   <REFSECT3 ID="R3-SQL-PRIMARYKEY-3">
    <REFSECT3INFO>
     <DATE>1998-09-11</DATE>
    </REFSECT3INFO>
    <TITLE>
d955 2
a956 2
    </TITLE>
    <PARA>
d960 2
a961 2
    </PARA>
    <PARA>
d968 1
a968 1
    </PARA>
d973 5
a977 5
 <REFSECT1 ID="R1-SQL-TABLECONSTRAINT-1">
  <REFSECT1INFO>
   <DATE>1998-09-11</DATE>
  </REFSECT1INFO>
  <TITLE>
d979 1
a979 1
  </TITLE>
d981 3
a983 2
   <SYNOPSIS>
    [ CONSTRAINT name ] { PRIMARY KEY |  UNIQUE } ( <replaceable class="parameter">column</replaceable> [, ...] )
d985 1
a985 1
   </SYNOPSIS>
d987 4
a990 4
  <REFSECT2 ID="R2-SQL-TABLECONSTRAINT-1">
   <REFSECT2INFO>
    <DATE>1998-09-11</DATE>
   </REFSECT2INFO>
d996 3
a998 3
    <VARIABLELIST>
     <VARLISTENTRY>
      <TERM>
d1000 3
a1002 3
      </TERM>
      <LISTITEM>
       <PARA>
d1004 5
a1008 5
       </PARA>
      </LISTITEM>
     </VARLISTENTRY>
     <VARLISTENTRY>
      <TERM>
d1010 3
a1012 3
      </TERM>
      <LISTITEM>
       <PARA>
d1015 2
a1016 2
       </PARA>
      </LISTITEM>
d1018 2
a1019 2
     <VARLISTENTRY>
      <TERM>
d1021 3
a1023 3
      </TERM>
      <LISTITEM>
       <PARA>
d1025 4
a1028 4
       </PARA>
      </LISTITEM>
     </VARLISTENTRY>
    </VARIABLELIST>
d1032 4
a1035 4
  <REFSECT2 ID="R2-SQL-TABLECONSTRAINT-2">
   <REFSECT2INFO>
    <DATE>1998-09-11</DATE>
   </REFSECT2INFO>
d1046 4
a1049 4
  <REFSECT2 ID="R2-SQL-TABLECONSTRAINT-3">
   <REFSECT2INFO>
    <DATE>1998-09-11</DATE>
   </REFSECT2INFO>
d1068 1
a1068 1
     (as of version 6.4) support FOREIGN KEY
d1077 5
a1081 5
  <REFSECT2 ID="R2-SQL-UNIQUECLAUSE-4">
   <REFSECT2INFO>
    <DATE>1998-09-11</DATE>
   </REFSECT2INFO>
   <TITLE>
d1083 1
a1083 1
   </TITLE>
d1086 3
a1088 2
     [ CONSTRAINT <replaceable class="parameter">name</replaceable> ] UNIQUE ( <replaceable class="parameter">column</replaceable> [, ...] )
    </SYNOPSIS>
d1118 4
a1121 4
    <PARA>
     <VARIABLELIST>
      <VARLISTENTRY>
       <TERM>
d1123 6
a1128 6
       </TERM>
       <LISTITEM>
	<PARA>
	 <VARIABLELIST>
	  <VARLISTENTRY>
	   <TERM>
d1151 1
a1151 1
    <PARA>
d1162 2
a1163 2
   <REFSECT3 ID="R3-SQL-UNIQUECLAUSE-4">
    <TITLE>
d1167 1
a1167 1
    <PARA>
d1169 1
a1169 1
     <ProgramListing>
d1175 1
a1175 1
     </ProgramListing>
d1178 1
a1178 1
  </REFSECT2>
d1180 5
a1184 5
  <REFSECT2 ID="R2-SQL-PRIMARYKEY-4">
   <REFSECT2INFO>
    <DATE>1998-09-11</DATE>
   </REFSECT2INFO>
   <TITLE>
d1186 1
a1186 1
   </TITLE>
d1188 4
a1191 3
    <SYNOPSIS>
     [ CONSTRAINT <REPLACEABLE CLASS="PARAMETER">name</REPLACEABLE> ] PRIMARY KEY ( <REPLACEABLE CLASS="PARAMETER">column</REPLACEABLE> [, ...] ) 
    </SYNOPSIS>
d1195 8
a1202 8
    <PARA>
     <VARIABLELIST>
      <VARLISTENTRY>
       <TERM>
	CONSTRAINT <ReturnValue><REPLACEABLE CLASS="PARAMETER">name</REPLACEABLE></ReturnValue>
       </TERM>
       <LISTITEM>
	<PARA>
d1204 9
a1212 9
	</PARA>
       </LISTITEM>
      </VARLISTENTRY>
      <VARLISTENTRY>
       <TERM>
	<REPLACEABLE CLASS="PARAMETER">column</REPLACEABLE> [, ...]
       </TERM>
       <LISTITEM>
	<PARA>
d1214 4
a1217 4
	</PARA>
       </LISTITEM>
      </VARLISTENTRY>
     </VARIABLELIST>
d1237 1
a1237 1
	   </PARA>
d1249 1
a1249 1
    <PARA>
d1258 2
a1259 2
    </PARA>
    <PARA>
d1263 1
a1263 1
   </REFSECT3>
d1265 1
a1265 1
  </REFSECT2>
d1269 2
a1270 2
 <REFSECT1 ID="R1-SQL-CREATETABLE-2">
  <TITLE>
d1272 2
a1273 2
  </TITLE>
  <PARA>
d1275 2
a1276 2
  </PARA>
  <ProgramListing>
d1285 1
a1285 1
  </ProgramListing>
d1287 1
a1287 1
  <ProgramListing>
d1292 1
a1292 1
  </ProgramListing>
d1294 1
a1294 1
  <PARA>
d1296 2
a1297 2
  </PARA>
  <ProgramListing>
d1301 1
a1301 1
  </ProgramListing>
d1303 1
a1303 1
  <PARA>
d1307 2
a1308 2
  </PARA>
  <ProgramListing>
d1318 1
a1318 1
  </ProgramListing>
d1320 1
a1320 1
  <PARA>
d1322 2
a1323 2
  </PARA>
  <ProgramListing>
d1328 1
a1328 1
  </ProgramListing>
d1330 1
a1330 1
  <PARA>
d1332 2
a1333 2
  </PARA>
  <ProgramListing>
d1339 1
a1339 1
  </ProgramListing>
d1341 1
a1341 1
  <PARA>
d1345 2
a1346 2
  </PARA>
  <ProgramListing>
d1356 1
a1356 1
  </ProgramListing>
d1358 1
a1358 1
  <PARA>
d1362 2
a1363 2
  </PARA>
  <ProgramListing>
d1374 1
a1374 1
  </ProgramListing>
d1376 5
a1380 5
  <REFSECT2 ID="R2-SQL-CREATETABLE-3">
   <REFSECT2INFO>
    <DATE>1998-09-11</DATE>
   </REFSECT2INFO>
   <TITLE>
d1382 2
a1383 2
   </TITLE>
   <PARA>
d1386 1
a1386 1
   </PARA>
d1389 1
a1389 1
 </REFSECT1>
d1391 2
a1392 2
 <REFSECT1 ID="R1-SQL-CREATETABLE-3">
  <TITLE>
d1394 1
a1394 1
  </TITLE>
d1396 5
a1400 5
  <REFSECT2 ID="R2-SQL-CREATETABLE-4">
   <REFSECT2INFO>
    <DATE>1998-09-11</DATE>
   </REFSECT2INFO>
   <TITLE>
d1402 2
a1403 2
   </TITLE>
   <PARA>
d1406 1
a1406 1
   </PARA>
d1440 1
a1440 1
      (v6.4), to create a temporary
d1446 5
a1450 5
   <REFSECT3 ID="R3-SQL-UNIQUECLAUSE-1">
    <REFSECT3INFO>
     <DATE>1998-09-11</DATE>
    </REFSECT3INFO>
    <TITLE>
d1452 2
a1453 2
    </TITLE>
    <PARA>
d1458 1
a1458 1
    </PARA>
d1476 5
a1480 5
   <REFSECT3 ID="R3-SQL-NULL-1">
    <REFSECT3INFO>
     <DATE>1998-12-24</DATE>
    </REFSECT3INFO>
    <TITLE>
d1482 2
a1483 2
    </TITLE>
    <PARA>
d1492 1
a1492 1
   </REFSECT3>
d1494 5
a1498 5
   <REFSECT3 ID="R3-SQL-NOTNULL-4">
    <REFSECT3INFO>
     <DATE>1998-09-11</DATE>
    </REFSECT3INFO>
    <TITLE>
d1500 2
a1501 2
    </TITLE>
    <PARA>
d1504 1
a1504 1
    </PARA>
d1510 1
a1510 1
   </REFSECT3>
d1539 5
a1543 5
   <REFSECT3 ID="R3-SQL-CONSTRAINT-3">
    <REFSECT3INFO>
     <DATE>1998-09-11</DATE>
    </REFSECT3INFO>
    <TITLE>
d1545 2
a1546 2
    </TITLE>
    <PARA>
d1556 1
a1556 1
    <PARA>
d1568 1
a1568 1
    <PARA>
d1572 1
a1572 1
    <PARA>
d1659 5
a1663 5
   <REFSECT3 ID="R3-SQL-CHECK-4">
    <REFSECT3INFO>
     <DATE>1998-09-11</DATE>
    </REFSECT3INFO>
    <TITLE>
d1665 2
a1666 2
    </TITLE>
    <PARA>
d1669 1
a1669 1
    </PARA>
d1723 5
a1727 5
   <REFSECT3 ID="R3-SQL-PRIMARYKEY-1">
    <REFSECT3INFO>
     <DATE>1998-09-11</DATE>
    </REFSECT3INFO>
    <TITLE>
d1729 2
a1730 2
    </TITLE>
    <PARA>
d1733 1
a1733 1
    <PARA>
a1752 101
 </refsect1>
</refentry>


<REFENTRY ID="SQL-CREATETABLEAS">
 <REFMETA>
  <REFENTRYTITLE>
   CREATE TABLE AS
  </REFENTRYTITLE>
  <REFMISCINFO>SQL - Language Statements</REFMISCINFO>
 </REFMETA>
 <REFNAMEDIV>
  <REFNAME>
   CREATE TABLE AS
  </REFNAME>
  <REFPURPOSE>
   Creates a new table
  </REFPURPOSE>
 </refnamediv>
 <REFSYNOPSISDIV>
  <REFSYNOPSISDIVINFO>
   <DATE>1998-09-22</DATE>
  </REFSYNOPSISDIVINFO>
  <SYNOPSIS>
CREATE TABLE <REPLACEABLE CLASS="PARAMETER">table</REPLACEABLE> [ ( <REPLACEABLE CLASS="PARAMETER">column</REPLACEABLE> [, ...] ) ] AS <REPLACEABLE CLASS="PARAMETER">select_clause</REPLACEABLE>
  </SYNOPSIS>
  
  <REFSECT2 ID="R2-SQL-CREATETABLEAS-1">
   <REFSECT2INFO>
    <DATE>1998-09-22</DATE>
   </REFSECT2INFO>
   <TITLE>
    Inputs
   </TITLE>
   <PARA>
   
   <VARIABLELIST>
    <VARLISTENTRY>
     <TERM>
      <REPLACEABLE CLASS="PARAMETER">table</REPLACEABLE>
     </TERM>
     <LISTITEM>
      <PARA>
       The name of a new table to be created.
      </PARA>
     </LISTITEM>
    </VARLISTENTRY>

     <VARLISTENTRY>
     <TERM>
      <REPLACEABLE CLASS="PARAMETER">column</REPLACEABLE>
     </TERM>
     <LISTITEM>
      <PARA>
       The name of a column. Multiple column names can be specified using
a comma-delimited list of column names.
      </PARA>
     </LISTITEM>
    </VARLISTENTRY>
    
    <VARLISTENTRY>
     <TERM>
      <REPLACEABLE CLASS="PARAMETER">select_clause</REPLACEABLE>
     </TERM>
     <LISTITEM>
      <PARA>
A valid query statement. Refer to SELECT for a description of the
allowed syntax.
       </PARA>
      </LISTITEM>
     </VARLISTENTRY>
    </VARIABLELIST>
   </para>
  </refsect2>

  <REFSECT2 ID="R2-SQL-CREATETABLEAS-2">
   <REFSECT2INFO>
    <DATE>1998-09-22</DATE>
   </REFSECT2INFO>
   <TITLE>
    Outputs
   </TITLE>
   <PARA>
    Refer to CREATE TABLE and SELECT for a summary of possible output
    messages.
   </para>
  </refsect2>
 </refsynopsisdiv>
 
 <REFSECT1 ID="R1-SQL-CREATETABLEAS-1">
  <REFSECT1INFO>
   <DATE>1998-09-22</DATE>
  </REFSECT1INFO>
  <TITLE>
   Description
  </TITLE>
   <PARA>
CREATE TABLE AS enables a table to be created from the contents of
an existing table. It has functionality equivalent to SELECT TABLE INTO,
but with perhaps a more obvious syntax.
  </para>
@


1.13
log
@Minor markup changes for the recent TEMP TABLE info.
Docs should build now...
@
text
@d1485 1
d1854 1
a1854 1
sgml-omittag:t
@


1.12
log
@Add TEMP tables/indexes.  Add COPY pfree().  Other cleanups.
@
text
@d21 1
a21 1
CREATE [TEMP] TABLE <REPLACEABLE CLASS="PARAMETER">table</REPLACEABLE> (
d39 1
d42 1
d49 1
a49 1
	The table is created unique to this session, and is
d51 2
a56 1
   <VARIABLELIST>
@


1.11
log
@Clean up to ensure tag completion as required by the newest versions
 of Norm's Modular Style Sheets and jade/docbook.
From Vince Vielhaber <vev@@michvhf.com>.
@
text
@d21 1
a21 1
CREATE TABLE <REPLACEABLE CLASS="PARAMETER">table</REPLACEABLE> (
d41 12
@


1.10
log
@Minor cleanup in markup, especially in the Output section.
@
text
@d15 1
a15 1
  
d23 1
a23 2
    [ DEFAULT <REPLACEABLE CLASS="PARAMETER">value</REPLACEABLE>]
    [, NOT NULL ] [ ,UNIQUE ]
d128 26
a153 27
    <VARLISTENTRY>
     <TERM>
     INHERITS <REPLACEABLE CLASS="PARAMETER">inherited_table</REPLACEABLE>
     </TERM>
     <LISTITEM>
      <PARA>
       The optional INHERITS clause specifies a collection of table
       names from which this table automatically inherits all fields.
       If any inherited field name appears more than once, 
<productname>Postgres</productname>
       reports an error.
 <productname>Postgres</productname> automatically allows the created
       table to inherit functions on tables above it in the inheritance
       hierarchy.
<note>
<title>Aside</title>
<para>
 Inheritance of functions is done according
       to the conventions of the Common Lisp Object System (CLOS).
</note>
      </PARA>
     </LISTITEM>
    </VARLISTENTRY>
    
   </VARIABLELIST>
   
   
d202 5
a206 2

   </VARIABLELIST>
d221 1
a221 1
   
d230 1
a230 1
  
d232 1
a232 1
  <REFSECT1 ID="R1-SQL-DEFAULTCLAUSE-1">
d243 1
a243 1

d274 1
a274 4
	     </simpara>
	    </listitem>
	   </itemizedlist>
	  </para>
d276 8
a283 3
	</VARLISTENTRY>
	
       </variablelist>
d289 6
a294 4
   Outputs
  </TITLE>
  <PARA>

d373 1
d395 2
a396 1

d416 1
a416 1

d428 2
a429 1

d441 1
a441 1
[ CONSTRAINT <replaceable class="parameter">name</replaceable> ] { NOT NULL | UNIQUE | PRIMARY KEY | CHECK <replaceable class="parameter">constraint</replaceable> } [, ...]
d443 1
d471 11
d530 2
d569 1
d590 35
a624 62
  <REFSECT3 ID="R3-SQL-NOTNULL-1">
   <REFSECT3INFO>
    <DATE>1998-09-11</DATE>
   </REFSECT3INFO>
   <TITLE>
    Outputs
   </TITLE>
   <PARA>
   </PARA>
   <VARIABLELIST>
    <VARLISTENTRY>
     <TERM>
<replaceable>status</replaceable>
     </TERM>
     <LISTITEM>
      <PARA>
       <VARIABLELIST>
	<VARLISTENTRY>
	 <TERM>
	  <ReturnValue>ERROR:  ExecAppend: Fail to add null value in not
	   null attribute "<replaceable class="parameter">column</replaceable>".</ReturnValue>
	 </TERM>
	 <LISTITEM>
	  <PARA>
	   This error occurs at runtime if one tries to insert a null value
	   into a column which has a NOT NULL constraint.
	  </PARA>
	 </LISTITEM>
	</VARLISTENTRY>
       </variablelist>
     </LISTITEM>
    </VARLISTENTRY>
   </VARIABLELIST> 

  <REFSECT3 ID="R3-SQL-NOTNULL-2">
   <REFSECT3INFO>
    <DATE>1998-09-11</DATE>
   </REFSECT3INFO>
   <TITLE>
Description
</title>
<para>

  <REFSECT3 ID="R3-SQL-NOTNULL-3">
   <REFSECT3INFO>
    <DATE>1998-09-11</DATE>
   </REFSECT3INFO>
   <TITLE>
Usage
</title>

  <PARA>
   Define two NOT NULL column constraints on the table
 <classname>distributors</classname>,
one of which being a named constraint:
  </PARA>
  <ProgramListing>
CREATE TABLE distributors (
    did      DECIMAL(3) CONSTRAINT no_null NOT NULL,
    name     VARCHAR(40) NOT NULL
);
  </ProgramListing>
d626 34
d673 14
a686 13
<para>
    <variablelist>
     <varlistentry>
      <term>
      CONSTRAINT <replaceable class="parameter">name</replaceable>
      </term>
      <listitem>
       <para>
	An arbitrary label given to a constraint.
       </para>
      </listitem>
     </varlistentry>
    </variablelist>
d688 1
a688 1

d708 9
a716 7
	   </para>
	  </listitem>
	 </varlistentry>
	</variablelist></para>
      </listitem>
     </varlistentry>
    </variablelist>
d718 1
a718 1

d749 1
d774 3
d799 3
a801 25
	  </PARA>
	 </LISTITEM>
	</VARLISTENTRY>
	<VARLISTENTRY>
	 <TERM>
	  <replaceable>condition</replaceable>
	 </TERM>
	 <LISTITEM>
	  <PARA>
	   Any valid conditional expression evaluating to a boolean result.
	  </PARA>
	 </LISTITEM>
	</VARLISTENTRY>
       </variablelist>
  </REFSECT3>

  <REFSECT3 ID="R3-SQL-CHECK-2">
   <REFSECT3INFO>
    <DATE>1998-09-11</DATE>
   </REFSECT3INFO>
    <TITLE>
     Outputs
    </TITLE>
    <PARA>
     <VARIABLELIST>
d804 1
a804 1
<replaceable>status</replaceable>
d808 16
a823 1

d827 1
a827 4
	<ReturnValue>
	 ERROR:  ExecAppend: rejected due to CHECK constraint
	 "<replaceable class="parameter">table_column</replaceable>".
	</ReturnValue>
d831 18
a848 6
	 This error occurs at runtime if one tries to insert an illegal
	 value into a column subject to a CHECK constraint.
	</PARA>
       </LISTITEM>
      </VARLISTENTRY>
     </variablelist>
d852 1
d854 1
a854 1

d859 1
a859 1
within a column.
d865 1
a865 1
 does not have
d911 1
a911 1
      </PARA>
d952 8
a959 6

  <REFSECT1 ID="R1-SQL-TABLECONSTRAINT-1">
   <REFSECT1INFO>
    <DATE>1998-09-11</DATE>
   </REFSECT1INFO>
   <TITLE>
d961 2
a962 2
   </TITLE>
   <para>
d964 2
a965 2
[ CONSTRAINT name ] { PRIMARY KEY |  UNIQUE } ( <replaceable class="parameter">column</replaceable> [, ...] )
[ CONSTRAINT name ] CHECK ( <replaceable>constraint</replaceable> )
d967 1
a967 2
   <PARA>

d972 41
a1012 38
<title>
Inputs
</title>

<para>
       <VARIABLELIST>
	<VARLISTENTRY>
	 <TERM>
	 CONSTRAINT <replaceable class="parameter">name</replaceable>
	 </TERM>
	 <LISTITEM>
	  <PARA>
          An arbitrary name given to an integrity constraint.
	  </PARA>
	 </LISTITEM>
	</VARLISTENTRY>
	<VARLISTENTRY>
	 <TERM>
	   <replaceable class="parameter">column</replaceable> [, ...]
	 </TERM>
	 <LISTITEM>
	  <PARA>
	   The column name(s) for which to define a unique index
and, for PRIMARY KEY, a NOT NULL constraint.
	  </PARA>
	 </LISTITEM>
	<VARLISTENTRY>
	 <TERM>
	  CHECK ( <replaceable class="parameter">constraint</replaceable> )
	 </TERM>
	 <LISTITEM>
	  <PARA>
	   A boolean expression to be evaluated as the constraint.
	  </PARA>
	 </LISTITEM>
	</VARLISTENTRY>
       </VARIABLELIST>

d1017 10
a1026 8
<title>
Outputs
</title>

<para>
The possible outputs for the table constraint clause are the same
as for the corresponding portions of the column constraint clause.

d1031 4
a1034 4
<title>
Description
</title>

d1049 3
a1051 3
(as of version 6.4) support FOREIGN KEY
integrity constraints. The parser understands the FOREIGN KEY syntax,
but only prints a notice and otherwise ignores the clause.
d1056 2
a1057 1
   
d1066 4
a1069 3
   <synopsis>
[ CONSTRAINT <replaceable class="parameter">name</replaceable> ] UNIQUE ( <replaceable class="parameter">column</replaceable> [, ...] )
   </SYNOPSIS>
d1075 1
a1075 1
      CONSTRAINT <replaceable class="parameter">name</replaceable>
d1095 1
d1099 25
a1123 23
    <VARIABLELIST>
     <VARLISTENTRY>
      <TERM>
<replaceable>status</replaceable>
      </TERM>
      <LISTITEM>
       <PARA>
	<VARIABLELIST>
	 <VARLISTENTRY>
	  <TERM>
	   ERROR: Cannot insert a duplicate key into a unique index.
	  </term>
	  <listitem>
	   <para>
	    This error occurs at runtime if one tries to insert a
	    duplicate value into a column.
	   </para>
	  </listitem>
	 </varlistentry>
	</variablelist>
      </listitem>
     </varlistentry>
    </variablelist>
d1125 1
a1125 1

d1128 1
a1128 1
Description
d1130 1
a1130 1

d1134 2
a1135 2
The behavior of the UNIQUE table constraint is the same as that for column
constraints, with the additional capability to span multiple columns.
d1138 3
a1140 17
See the section on the UNIQUE column constraint for more details.

  <REFSECT3 ID="R3-SQL-UNIQUECLAUSE-4">
   <TITLE>
Usage
</title>

  <PARA>
   Define a UNIQUE table constraint for the table distributors:
  <ProgramListing>
CREATE TABLE distributors (
    did      DECIMAL(03),
    name     VARCHAR(40),
    UNIQUE(name)
);
  </ProgramListing>

d1142 16
d1167 5
a1171 5
<para>
   <SYNOPSIS>
    [ CONSTRAINT <REPLACEABLE CLASS="PARAMETER">name</REPLACEABLE> ] PRIMARY KEY ( <REPLACEABLE CLASS="PARAMETER">column</REPLACEABLE> [, ...] ) 
   </SYNOPSIS>
   
d1178 1
a1178 1
CONSTRAINT <ReturnValue><REPLACEABLE CLASS="PARAMETER">name</REPLACEABLE></ReturnValue>
d1188 1
a1188 1
<REPLACEABLE CLASS="PARAMETER">column</REPLACEABLE> [, ...]
d1199 1
a1199 1

d1205 2
a1206 7
<replaceable>status</replaceable>
</term>
<listitem>
<para>
    <variablelist>
     <varlistentry>
      <term>ERROR: Cannot insert a duplicate key into a unique index.</term>
d1209 12
a1220 6
	This occurs at run-time if one tries to insert a duplicate value into
	a column subject to a PRIMARY KEY constraint.
      </PARA>
      </listitem>
     </varlistentry>
    </variablelist>
d1225 1
a1225 1

d1234 3
a1236 3

The PRIMARY KEY table constraint is similar to that for column constraints,
with the additional capability of encompassing multiple columns.
d1239 3
a1241 2
Refer to the section on the PRIMARY KEY column constraint for more
information.
d1245 1
a1245 1

d1364 1
a1364 1
 language extension.
a1373 1
  <PARA>
d1414 11
a1424 9
Temporary tables are not currently available
 in <productname>Postgres</productname>.
<tip>
   <para>
    In the current release of <productname>Postgres</productname>
 (v6.4), to create a temporary
    table you must create and drop the table by explicit commands.
</tip>
   
d1434 1
d1455 17
d1484 3
a1486 3
      [ CONSTRAINT name ] NOT NULL 
      [ {INITIALLY DEFERRED | INITIALLY IMMEDIATE} ]
      [ [ NOT ] DEFERRABLE ]
d1527 6
a1532 4
   <note>
    <para>
     <productname>Postgres</productname> does not yet support 
either domains or assertions.
a1533 2
   </note>

d1749 1
a1749 1
  
d1799 6
a1804 4
      </PARA>
     </LISTITEM>
    </VARLISTENTRY>
   </VARIABLELIST>
d1814 13
a1826 10
   Refer to CREATE TABLE and SELECT for a summary of possible output
messages.

  <REFSECT1 ID="R1-SQL-CREATETABLEAS-1">
   <REFSECT1INFO>
    <DATE>1998-09-22</DATE>
   </REFSECT1INFO>
   <TITLE>
    Description
   </TITLE>
d1831 2
a1832 2

</refsect1>
@


1.9
log
@Minor fixes in markup.
Include cross-references in NOTIFY and UNLISTEN.
@
text
@d166 1
a166 8
   </PARA>
   <VARIABLELIST>
    <VARLISTENTRY>
     <TERM>
      <ReturnValue>status</ReturnValue>
     </TERM>
     <LISTITEM>
      <PARA>
a203 3
	  </PARA>
	 </LISTITEM>
	</VARLISTENTRY>
a204 4
       </VARIABLELIST>
      </PARA>
     </LISTITEM>
    </VARLISTENTRY>
d1664 1
a1664 1
   CREATE TABLE
d1670 1
a1670 1
   CREATE TABLE
@


1.8
log
@SGML updates from post 6.3.2 manual changes.  Added pg_upgrade man page.
@
text
@d120 1
a120 2
       The use of
       <TERM>
d122 2
a123 7
       </TERM>
       as a table constraint
       is mutually incompatible with
       <TERM>
       PRIMARY KEY
       </TERM>
       used as a column constraint.
@


1.7
log
@Cleanup markup and minor editing to prepare for first release.
@
text
@d22 4
a25 1
    <REPLACEABLE CLASS="PARAMETER">column</REPLACEABLE> <REPLACEABLE CLASS="PARAMETER">type</REPLACEABLE> [ DEFAULT <REPLACEABLE CLASS="PARAMETER">value</REPLACEABLE> | <REPLACEABLE>column_constraint_clause</REPLACEABLE> | PRIMARY KEY } [ ... ] ]
d28 1
d96 2
a97 2
       The optional column constraint clause specifies a list of integrity 
       constraints which new or updated entries must satisfy for
d120 10
@


1.6
log
@Editing and markup cleanup.
@
text
@d1666 96
@


1.5
log
@Very minor formatting fixup in the refentry id field to remove
 the trailing "-1". This makes a cleaner html output file name.
Clean up a few refpurpose fields.
@
text
@d18 1
a18 1
   <DATE>1998-04-15</DATE>
d21 6
a26 5
   CREATE TABLE <REPLACEABLE CLASS="PARAMETER">table</REPLACEABLE> (
        <REPLACEABLE CLASS="PARAMETER">column</REPLACEABLE> <REPLACEABLE CLASS="PARAMETER">type</REPLACEABLE> [DEFAULT <REPLACEABLE CLASS="PARAMETER">value</REPLACEABLE>] [CONSTRAINT <REPLACEABLE CLASS="PARAMETER">column_constraint</REPLACEABLE>] [, ...]
        [, <REPLACEABLE CLASS="PARAMETER">column</REPLACEABLE> ...]
        [, CONSTRAINT <REPLACEABLE CLASS="PARAMETER">table_constraint</REPLACEABLE>]
        ) [INHERITS ( <REPLACEABLE CLASS="PARAMETER">inherited_table</REPLACEABLE> [, ...] )]
d31 1
a31 1
    <DATE>1998-04-15</DATE>
a36 1
   </PARA>
d67 3
a69 3
       The type of the column.
       (Refer to the <ProductName>Postgres</ProductName> User's Guide for
       further information about data types).
d76 1
a76 1
      <REPLACEABLE CLASS="PARAMETER">value</REPLACEABLE>
d88 1
a88 1
      <REPLACEABLE CLASS="PARAMETER">inherited_table</REPLACEABLE>
d92 9
a100 7
       The optional INHERITS clause specifies a collection of table
       names from which this table automatically inherits all fields.
       If any inherited field name appears more than once, PostgreSQL
       reports an error. PostgreSQL automatically allows the created
       table to inherit functions on tables above it in the inheritance
       hierarchy. Inheritance of functions is done according
       to the conventions of the Common Lisp Object System (CLOS).
d104 1
a104 1
    
d107 1
a107 2
      <REPLACEABLE CLASS="PARAMETER">column_constraint</REPLACEABLE>
      <REPLACEABLE CLASS="PARAMETER">table_constraint</REPLACEABLE>
d111 1
a111 1
       The optional CONSTRAINT clause specifies a list of integrity 
d116 25
a140 1
       See CONSTRAINT clause for more information.
d144 1
d152 1
a152 1
    <DATE>1998-04-15</DATE>
d187 1
a187 1
   amcreate: "<replaceable class="parameter">table</replaceable>" relation already exists
d194 13
d217 1
a217 1
   <DATE>1998-04-15</DATE>
d223 1
a223 1
   CREATE TABLE will enter a new table into the current data
d236 5
a240 4
  <REFSECT2 ID="R2-SQL-DEFAULTCLAUSE-1">
   <REFSECT2INFO>
    <DATE>1998-04-15</DATE>
   </REFSECT2INFO>
d242 1
a242 1
    DEFAULT clause
d246 1
a246 1
     DEFAULT <REPLACEABLE CLASS="PARAMETER">value</REPLACEABLE>
d248 9
a256 9
   <PARA>
    The DEFAULT clause assigns a default data value to a column.
   </PARA>
   <VARIABLELIST>
    <VARLISTENTRY>
     <TERM>
     </TERM>
     <LISTITEM>
      <PARA>
d260 1
a260 1
	  <ReturnValue><replaceable class="parameter">value</replaceable></ReturnValue>
d264 1
a264 1
	   The possible values for expression are:
a285 11
	<VARLISTENTRY>
	 <TERM>
	  <ReturnValue>ERROR:  DEFAULT: type mismatched</ReturnValue>
	 </TERM>
	 <LISTITEM>
	  <PARA>
	   if data type of default value doesn't match the
	   column definition's data type.
	  </PARA>
	 </LISTITEM>
	</VARLISTENTRY>
d287 17
a303 1
      <PARA>
d321 2
a322 1
       There are two types of niladic functions:<variablelist>
d374 128
d504 50
a553 3
   </VARIABLELIST>
  </REFSECT2>
  
d556 1
a556 1
    <DATE>1998-04-15</DATE>
d559 1
a559 1
    NOT NULL constraint
d562 1
a562 1
    [ CONSTRAINT <replaceable class="parameter">name</replaceable> ] NOT NULL 
d569 12
a580 1
    The NOT NULL constraint is a column constraint. 
d585 1
d592 2
a593 1
	  <ReturnValue><replaceable class="parameter">name</replaceable></ReturnValue>
d597 2
a598 1
	   The optional name of a constraint.
d605 141
a745 1
   </VARIABLELIST>
d747 38
a784 1
  <REFSECT3 ID="R3-SQL-NOTNULL-1">
d786 1
a786 1
    <DATE>1998-04-15</DATE>
d788 135
d924 1
a924 1
    Outputs
d926 5
d932 10
a941 7
   </PARA>
   <VARIABLELIST>
    <VARLISTENTRY>
     <TERM>
     </TERM>
     <LISTITEM>
      <PARA>
d945 21
a965 2
	  <ReturnValue>ERROR:  ExecAppend: Fail to add null value in not
	   null attribute "<replaceable class="parameter">column</replaceable>".</ReturnValue>
d969 49
a1017 13
	   This error occurs at runtime if one tries to insert a null value
	   into a column which has a NOT NULL constraint.
	  </PARA>
	 </LISTITEM>
	</VARLISTENTRY>
       </variablelist>
     </LISTITEM>
    </VARLISTENTRY>
   </VARIABLELIST> 
  </REFSECT3>
  </REFSECT2>
  
  <REFSECT2 ID="R2-SQL-UNIQUECLAUSE-1">
d1019 1
a1019 1
    <DATE>1998-04-15</DATE>
d1022 1
a1022 1
    UNIQUE constraint
a1024 8
    Table Constraint definition
   </para>
   <synopsis>
    [ CONSTRAINT <replaceable class="parameter">name</replaceable> ] UNIQUE ( <replaceable class="parameter">column</replaceable> [, ...] )
   </SYNOPSIS>
   <para>
    Column Constraint definition
   </para>
d1026 1
a1026 1
    [ CONSTRAINT <replaceable class="parameter">name</replaceable> ] UNIQUE
d1029 1
a1029 1
    <title>Parameters</title>
d1033 1
a1033 1
       <replaceable class="parameter">name</replaceable>
a1055 1
    </PARA>
d1059 1
d1075 1
a1075 1
	</variablelist></para>
d1080 1
d1082 4
a1085 1
    <title>Description</title>
d1089 2
d1093 3
a1095 23
     The column definitions of the specified columns do not have to
     include a NOT NULL constraint to be included in a UNIQUE
     constraint.  Having more than one null value in a column without a
     NOT NULL constraint, does not violate a UNIQUE constraint.
    </PARA>
    <PARA>
     Each UNIQUE 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.
    </PARA>
    <Note>
     <Para>
      PostgreSQL automatically creates a unique index for each UNIQUE
      constraint, to assure
      data integrity. See CREATE INDEX for more information.
     </Para>
    </Note>
  </REFSECT2>
  
  <REFSECT2 ID="R2-SQL-CONSTRAINT-1">
   <REFSECT2INFO>
    <DATE>1998-04-15</DATE>
   </REFSECT2INFO>
d1097 14
a1110 104
    CONSTRAINT clause
   </TITLE>
   <para>
    Table constraint definition
   </para>
   <SYNOPSIS>
    [ CONSTRAINT name ] 
    { PRIMARY KEY constraint | 
    UNIQUE constraint | 
    CHECK constraint }  
   </SYNOPSIS>
   <PARA>
    Column constraint definition 
   </PARA>
   <SYNOPSIS>
    [ CONSTRAINT name ] 
    { NOT NULL constraint |
    PRIMARY KEY constraint | 
    UNIQUE constraint | 
    CHECK constraint }  
   </SYNOPSIS>
   <PARA>
   </PARA>
   <VARIABLELIST>
    <VARLISTENTRY>
     <TERM>
     </TERM>
     <LISTITEM>
      <PARA>
       <VARIABLELIST>
	<VARLISTENTRY>
	 <TERM>
	  <ReturnValue>
	   <replaceable class="parameter">name</replaceable>
	  </ReturnValue>
	 </TERM>
	 <LISTITEM>
	  <PARA>
          An arbitrary name given to an integrity constraint.
	  </PARA>
	 </LISTITEM>
	</VARLISTENTRY>
	<VARLISTENTRY>
	 <TERM>
	  <ReturnValue>
	   <replaceable class="parameter">constraint</replaceable>
	  </ReturnValue>
	 </TERM>
	 <LISTITEM>
	  <PARA>
	   The definition of the constraint.
	  </PARA>
	 </LISTITEM>
	</VARLISTENTRY>
       </VARIABLELIST>
     </LISTITEM>
    </VARLISTENTRY>
   </VARIABLELIST>
   <para>
    A Constraint is a named rule: a SQL object which helps define
    valid sets of values by putting limits on the results of INSERT,
    UPDATE or DELETE operations performed on a Base table. 
   </para>
   <para>
    There are two ways to define integrity constraints:
    Table constraint and Column constraint.
   </para>
   <para>
    A Table Constraint is an integrity Constraint defined on one or
    more Columns of a Base table. The four variations of "Table
    Constraint" are:
    <simplelist columns="1">
     <member>PRIMARY KEY</member>
     <member>FOREIGN KEY</member>
     <member>UNIQUE</member>
     <member>CHECK</member>
    </simplelist>
   </para>
   <para>
    A column constraint is an integrity constraint defined as part
    of a column definition, and logically becomes a table
    constraint as soon as it is created. The column
    constraints available are:
    <simplelist columns="1">
     <member>PRIMARY KEY</member>
     <member>REFERENCES</member>
     <member>UNIQUE</member>
     <member>CHECK</member>
     <member>NOT NULL</member>
    </simplelist></para>
   <note>
    <para>
     PostgreSQL does not yet (at release 6.3.2) support the FOREIGN KEY or
     REFERENCES integrity constraints, although the parser will accept them.
     Foreign keys may be partially emulated by triggers (See CREATE TRIGGER
     statement)
    </para>
   </note>
   <note>
    <para>
     PostgreSQL does not yet support either DOMAINs or ASSERTIONs.
    </para>
   </note>
   
a1111 35
  
  <REFSECT2 ID="R2-SQL-CHECK-1">
   <REFSECT2INFO>
    <DATE>1998-04-15</DATE>
   </REFSECT2INFO>
   <title>The CHECK constraint</title>
  <SYNOPSIS>
   [ CONSTRAINT name ] CHECK ( condition [, ...] ) 
  </SYNOPSIS>
   <refsect3 id="R3-SQL-CHECK-1">
    <title>Inputs</title>
   <PARA>
       <VARIABLELIST>
	<VARLISTENTRY>
	 <TERM>
	  <ReturnValue><replaceable class="parameter">name</replaceable></ReturnValue>
	 </TERM>
	 <LISTITEM>
	  <PARA>
	   An arbitrary name given to a constraint.
	  </PARA>
	 </LISTITEM>
	</VARLISTENTRY>
	<VARLISTENTRY>
	 <TERM>
	  <ReturnValue>condition</ReturnValue>
	 </TERM>
	 <LISTITEM>
	  <PARA>
	   Any valid conditional expression.
	  </PARA>
	 </LISTITEM>
	</VARLISTENTRY>
       </variablelist>
  </REFSECT3>
d1113 1
a1113 45
  <REFSECT3 ID="R3-SQL-CHECK-2">
   <REFSECT3INFO>
    <DATE>1998-04-15</DATE>
   </REFSECT3INFO>
    <TITLE>
     Outputs
    </TITLE>
    <PARA>
     <VARIABLELIST>
      <VARLISTENTRY>
       <TERM>
	<ReturnValue>
	 ERROR:  ExecAppend: rejected due to CHECK constraint
	 "<replaceable class="parameter">table_column</replaceable>".
	</ReturnValue>
       </TERM>
       <LISTITEM>
	<PARA>
	 This error occurs at runtime if one tries to insert an illegal
	 value into a column subject to a CHECK constraint.
	</PARA>
       </LISTITEM>
      </VARLISTENTRY>
     </variablelist>
   </REFSECT3>
   <refsect3>
    <title>Description</title>
    <para>
     The CHECK constraint specifies a rule that a group of one or
     more columns of a table may contain only those values allowed by
     the rule.
     The CHECK constraint is either a table constraint or a column
     constraint.
    </PARA>
    <PARA>
     PostgreSQL automatically creates an unique index to assure
     data integrity (See CREATE INDEX statement).
     The SQL92 CHECK column constraints can only be defined on, and
     refer to, one column of the table. PostgreSQL does not have
     this restriction.
    </PARA>
   </refsect3>
  </REFSECT2>
  
  <REFSECT2 ID="R2-SQL-PRIMARYKEY-1">
d1115 1
a1115 1
    <DATE>1998-04-15</DATE>
d1118 1
a1118 1
    PRIMARY KEY clause
d1120 1
a1120 3
   <PARA>
   Table constraint definition
   </PARA>
a1123 6
   <PARA>
    Column constraint definition
   </PARA> 
   <SYNOPSIS>
    [ CONSTRAINT <REPLACEABLE CLASS="PARAMETER">name</REPLACEABLE> ] PRIMARY KEY 
   </SYNOPSIS>
d1126 1
a1126 1
    <title>Parameters</title>
d1131 1
a1131 1
	<ReturnValue><REPLACEABLE CLASS="PARAMETER">name</REPLACEABLE></ReturnValue>
d1141 1
a1141 1
	<ReturnValue><REPLACEABLE CLASS="PARAMETER">column</REPLACEABLE></ReturnValue>
d1145 1
a1145 1
	 The name of a column in the table.
d1152 1
d1157 7
d1173 3
d1177 1
d1183 1
a1183 1
     (not duplicates), non-null values. The column definitions of
d1185 4
a1188 5
     constraint to be included in a PRIMARY KEY constraint. 
    </PARA>
    <PARA>
     A table's set of valid values may be constrained by only one
     PRIMARY KEY constraint at a time. 
d1191 2
a1192 4
     The PRIMARY KEY constraint must name a set of columns that is
     different from the set of columns named by any UNIQUE constraint
     defined for the same table. 
    </PARA>
a1194 13
   <REFSECT3 ID="R3-SQL-PRIMARYKEY-3">
    <REFSECT3INFO>
     <DATE>1998-04-15</DATE>
    </REFSECT3INFO>
    <TITLE>
     Notes
    </TITLE>
    <PARA>
     PostgreSQL automatically creates an unique index to assure
     data integrity. (See CREATE INDEX statement)
    </PARA>
   </refsect3>
   
d1196 1
a1233 10
   Define two NOT NULL column constraints on the table distributors
  </PARA>
  <ProgramListing>
   CREATE TABLE distributors (
        did      DECIMAL(3) CONSTRAINT no_null NOT NULL,
        name     VARCHAR(40) NOT NULL
        );
  </ProgramListing>

  <PARA>
a1250 20
   Defines a UNIQUE column constraint for the table distributors.
   UNIQUE column constraints can only be defined on one column
   of the table (the following two examples are equivalents).
  </PARA>
  <ProgramListing>
   CREATE TABLE distributors (
        did      DECIMAL(03),
        name     VARCHAR(40) UNIQUE,
        UNIQUE(name)
        );
  </ProgramListing>

  <ProgramListing>
   CREATE TABLE distributors (
        did      DECIMAL(3),
        name     VARCHAR(40) UNIQUE
        );
  </ProgramListing>

  <PARA>
d1291 1
a1291 1
   of the table (the following two examples are equivalents)
a1304 11
  <para>
   To assign a sequence as the default for the column did,
   and a literal to the column name
  </PARA>
  
  <ProgramListing>
       CREATE TABLE distributors (
              did      DECIMAL(3) DEFAULT NEXTVAL('serial'),
              name     VARCHAR(40) DEFAULT 'luso films'
              );
  </ProgramListing>
d1308 1
a1308 1
    <DATE>1998-04-15</DATE>
d1314 2
a1315 1
    CREATE TABLE/INHERITS is a PostgreSQL language extension.
a1325 1
  </PARA>
d1329 1
a1329 1
    <DATE>1998-04-15</DATE>
d1335 1
a1335 1
    In addition to normal CREATE TABLE, SQL92 also defines a
d1366 2
a1367 1
Temporary tables are not currently available in <productname>Postgres</productname>.
d1370 2
a1371 1
    In the current release of <productname>Postgres</productname> (v6.4), to create a temporary
d1377 1
a1377 1
     <DATE>1998-04-15</DATE>
d1406 1
a1406 1
     <DATE>1998-04-15</DATE>
d1431 1
a1431 1
     <DATE>1998-04-15</DATE>
d1451 1
a1451 1
     <DATE>1998-04-15</DATE>
d1457 1
a1457 1
     SQL92 specifies some additional capabilities for CONSTRAINTs,
d1459 7
a1465 1
    </PARA>
d1571 1
a1571 1
     <DATE>1998-04-15</DATE>
d1635 1
a1635 1
     <DATE>1998-04-15</DATE>
@


1.4
log
@Enhanced the allowed constraint syntax, so remove mention of the problem.
@
text
@d1 1
a1 1
<REFENTRY ID="SQL-CREATETABLE-1">
@


1.3
log
@Make minor formatting improvements to statement synopses.
Make sure all files end with a newline.
@
text
@a680 2
    </para>
    <PARA>
d686 1
a686 3
     data integrity. (See CREATE INDEX statement)
    </PARA>
    <PARA>
a691 14
   <refsect3>
    <title>BUGS in CHECK constraint</title>
    <PARA>
     The following CHECK constraints gives a parse error like:
     <programlisting>
      ERROR:  parser: parse error at or near "opname":
     </programlisting>
     <simplelist columns="1">
      <member>CHECK ( <replaceable class="parameter">column</replaceable> BETWEEN 'A' AND 'Z' )</member>
      <member>CHECK ( <replaceable class="parameter">column</replaceable> IN ('A','Z'))</member>
      <member>CHECK ( <replaceable class="parameter">column</replaceable> NOT LIKE 'A%')</member>
     </simplelist>
    </para>
   </refsect3>
d1000 1
d1002 1
a1002 1
    TIP: In the current release of <productname>Postgres</productname> (v6.3.2), to create a temporary
d1004 1
a1004 1
   </para>
d1053 7
d1073 3
a1075 4
     DEFAULT <replaceable class="parameter">literal</replaceable> |
              niladic USER function |
              niladic datetime function |
              NULL
d1078 1
d1089 1
a1089 1
     it also defines assertions and domain constraints.
d1202 2
a1203 1
     SQL92 specifies some additional capabilities for CHECK:
d1205 5
d1214 1
d1233 1
d1254 1
@


1.2
log
@Fix minor end-of-file formatting.
@
text
@d13 1
a13 1
   Creates a new table.
d986 2
a987 2
    In addition to normal CREATE TABLE, SQL92 also supports a
    CREATE TEMPORARY TABLE statement.
d1017 3
a1019 1
    TIP: In the current release of PostgreSQL (6.3.2), to create a temporary
d1032 1
d1307 1
a1307 1
-->@


1.1
log
@First version of files from Oliver Elphick.
@
text
@d1304 1
a1304 1
-->
@
