Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
f58eac82
Commit
f58eac82
authored
Oct 13, 2006
by
Tom Lane
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code and docs review for ALTER TABLE INHERIT/NO INHERIT patch.
parent
e1fdd226
Changes
8
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
290 additions
and
303 deletions
+290
-303
doc/src/sgml/ddl.sgml
doc/src/sgml/ddl.sgml
+78
-102
doc/src/sgml/ref/alter_table.sgml
doc/src/sgml/ref/alter_table.sgml
+14
-17
src/backend/commands/tablecmds.c
src/backend/commands/tablecmds.c
+182
-165
src/backend/nodes/copyfuncs.c
src/backend/nodes/copyfuncs.c
+1
-2
src/backend/nodes/equalfuncs.c
src/backend/nodes/equalfuncs.c
+1
-2
src/backend/parser/gram.y
src/backend/parser/gram.y
+7
-7
src/include/nodes/parsenodes.h
src/include/nodes/parsenodes.h
+4
-5
src/test/regress/expected/alter_table.out
src/test/regress/expected/alter_table.out
+3
-3
No files found.
doc/src/sgml/ddl.sgml
View file @
f58eac82
This diff is collapsed.
Click to expand it.
doc/src/sgml/ref/alter_table.sgml
View file @
f58eac82
<!--
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_table.sgml,v 1.9
0 2006/09/16 00:30:16 momjian
Exp $
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_table.sgml,v 1.9
1 2006/10/13 21:43:18 tgl
Exp $
PostgreSQL documentation
-->
...
...
@@ -294,28 +294,22 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
<term><literal>INHERIT <replaceable class="PARAMETER">parent_table</replaceable></literal></term>
<listitem>
<para>
This form adds a new parent table to the table. This won't add new
columns to the child table, instead all columns of the parent table must
already exist in the child table. They must have matching data types,
This form adds the target table as a new child of the specified parent
table. Subsequently, queries against the parent will include records
of the target table. To be added as a child, the target table must
already contain all the same columns as the parent (it could have
additional columns, too). The columns must have matching data types,
and if they have <literal>NOT NULL</literal> constraints in the parent
then they must also have <literal>NOT NULL</literal> constraints in the
child.
</para>
<para>
There must also be matching table constraints for all
<literal>CHECK</literal>
table
constraints of the parent. Currently
There must also be matching
child-
table constraints for all
<literal>CHECK</literal> constraints of the parent. Currently
<literal>UNIQUE</literal>, <literal>PRIMARY KEY</literal>, and
<literal>FOREIGN KEY</literal> constraints are ignored however this may
change in the future.
</para>
<para>
The easiest way to create a suitable table is to create a table using
<literal>INHERITS</literal> and then remove it via <literal>NO
INHERIT</literal>. Alternatively create a table using
<literal>LIKE</literal> however note that <literal>LIKE</literal> does
not create the necessary constraints.
<literal>FOREIGN KEY</literal> constraints are not considered, but
this may change in the future.
</para>
</listitem>
</varlistentry>
...
...
@@ -324,7 +318,8 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
<term><literal>NO INHERIT <replaceable class="PARAMETER">parent_table</replaceable></literal></term>
<listitem>
<para>
This form removes a parent table from the list of parents of the table.
This form removes the target table from the list of children of the
specified parent table.
Queries against the parent table will no longer include records drawn
from the target table.
</para>
...
...
@@ -392,6 +387,8 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
You must own the table to use <command>ALTER TABLE</>.
To change the schema of a table, you must also have
<literal>CREATE</literal> privilege on the new schema.
To add the table as a new child of a parent table, you must own the
parent table as well.
To alter the owner, you must also be a direct or indirect member of the new
owning role, and that role must have <literal>CREATE</literal> privilege on
the table's schema. (These restrictions enforce that altering the owner
...
...
src/backend/commands/tablecmds.c
View file @
f58eac82
This diff is collapsed.
Click to expand it.
src/backend/nodes/copyfuncs.c
View file @
f58eac82
...
...
@@ -15,7 +15,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.35
1 2006/10/04 00:29:53 momjian
Exp $
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.35
2 2006/10/13 21:43:18 tgl
Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -1821,7 +1821,6 @@ _copyAlterTableCmd(AlterTableCmd *from)
COPY_SCALAR_FIELD
(
subtype
);
COPY_STRING_FIELD
(
name
);
COPY_NODE_FIELD
(
parent
);
COPY_NODE_FIELD
(
def
);
COPY_NODE_FIELD
(
transform
);
COPY_SCALAR_FIELD
(
behavior
);
...
...
src/backend/nodes/equalfuncs.c
View file @
f58eac82
...
...
@@ -18,7 +18,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.28
5 2006/10/04 00:29:53 momjian
Exp $
* $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.28
6 2006/10/13 21:43:18 tgl
Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -768,7 +768,6 @@ _equalAlterTableCmd(AlterTableCmd *a, AlterTableCmd *b)
{
COMPARE_SCALAR_FIELD
(
subtype
);
COMPARE_STRING_FIELD
(
name
);
COMPARE_NODE_FIELD
(
parent
);
COMPARE_NODE_FIELD
(
def
);
COMPARE_NODE_FIELD
(
transform
);
COMPARE_SCALAR_FIELD
(
behavior
);
...
...
src/backend/parser/gram.y
View file @
f58eac82
...
...
@@ -11,7 +11,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.56
6 2006/09/28 20:51:42
tgl Exp $
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.56
7 2006/10/13 21:43:19
tgl Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
...
...
@@ -1506,20 +1506,20 @@ alter_table_cmd:
n->subtype = AT_DisableTrigUser;
$$ = (Node *)n;
}
/* ALTER TABLE <name>
ALTER INHERITS ADD
<parent> */
/* ALTER TABLE <name>
INHERIT
<parent> */
| INHERIT qualified_name
{
AlterTableCmd *n = makeNode(AlterTableCmd);
n->subtype = AT_AddInherit
s
;
n->
parent =
$2;
n->subtype = AT_AddInherit;
n->
def = (Node *)
$2;
$$ = (Node *)n;
}
/* ALTER TABLE <name>
alter INHERITS DROP
<parent> */
/* ALTER TABLE <name>
NO INHERIT
<parent> */
| NO INHERIT qualified_name
{
AlterTableCmd *n = makeNode(AlterTableCmd);
n->subtype = AT_DropInherit
s
;
n->
parent =
$3;
n->subtype = AT_DropInherit;
n->
def = (Node *)
$3;
$$ = (Node *)n;
}
| alter_rel_cmd
...
...
src/include/nodes/parsenodes.h
View file @
f58eac82
...
...
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.33
2 2006/10/11 16:42:5
9 tgl Exp $
* $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.33
3 2006/10/13 21:43:1
9 tgl Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -905,8 +905,8 @@ typedef enum AlterTableType
AT_DisableTrigAll
,
/* DISABLE TRIGGER ALL */
AT_EnableTrigUser
,
/* ENABLE TRIGGER USER */
AT_DisableTrigUser
,
/* DISABLE TRIGGER USER */
AT_AddInherit
s
,
/* ADD INHERITS
parent */
AT_DropInherit
s
/* DROP INHERITS
parent */
AT_AddInherit
,
/* INHERIT
parent */
AT_DropInherit
/* NO INHERIT
parent */
}
AlterTableType
;
typedef
struct
AlterTableCmd
/* one subcommand of an ALTER TABLE */
...
...
@@ -915,9 +915,8 @@ typedef struct AlterTableCmd /* one subcommand of an ALTER TABLE */
AlterTableType
subtype
;
/* Type of table alteration to apply */
char
*
name
;
/* column, constraint, or trigger to act on,
* or new owner or tablespace */
RangeVar
*
parent
;
/* Parent table for add/drop inherits */
Node
*
def
;
/* definition of new column, column type,
* index,
or constraint
*/
* index,
constraint, or parent table
*/
Node
*
transform
;
/* transformation expr for ALTER TYPE */
DropBehavior
behavior
;
/* RESTRICT or CASCADE for DROP cases */
}
AlterTableCmd
;
...
...
src/test/regress/expected/alter_table.out
View file @
f58eac82
...
...
@@ -324,7 +324,7 @@ select test2 from atacc2;
-- fail due to missing constraint
alter table atacc2 add constraint foo check (test2>0);
alter table atacc3 inherit atacc2;
ERROR: child table
missing constraint matching parent table
constraint "foo"
ERROR: child table
is missing
constraint "foo"
-- fail due to missing column
alter table atacc3 rename test2 to testx;
alter table atacc3 inherit atacc2;
...
...
@@ -342,10 +342,10 @@ alter table atacc3 inherit atacc2;
alter table atacc3 inherit atacc2;
ERROR: inherited relation "atacc2" duplicated
alter table atacc2 inherit atacc3;
ERROR: circular inheritance
structure foun
d
ERROR: circular inheritance
not allowe
d
DETAIL: "atacc3" is already a child of "atacc2".
alter table atacc2 inherit atacc2;
ERROR: circular inheritance
structure foun
d
ERROR: circular inheritance
not allowe
d
DETAIL: "atacc2" is already a child of "atacc2".
-- test that we really are a child now (should see 4 not 3 and cascade should go through)
select test2 from atacc2;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment