Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb9a3ef5

Browse files
committed
Remove unnecessairly duplicated gram.y productions
Declarative partitioning duplicated the TypedTableElement productions,evidently to remove the need to specify WITH OPTIONS when creatingpartitions. Instead, simply make WITH OPTIONS optional in theTypedTableElement production and remove all of the duplicatePartitionElement-related productions. This change simplifies thesyntax and makes WITH OPTIONS optional when adding defaults, constraintsor storage parameters to columns when creating either typed tables orpartitions.Also update pg_dump to no longer include WITH OPTIONS, since it's notnecessary, and update the documentation to reflect that WITH OPTIONS isnow optional.
1 parentab9c433 commitb9a3ef5

File tree

9 files changed

+94
-62
lines changed

9 files changed

+94
-62
lines changed

‎doc/src/sgml/ref/create_foreign_table.sgml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ CREATE FOREIGN TABLE [ IF NOT EXISTS ] <replaceable class="PARAMETER">table_name
2929

3030
CREATE FOREIGN TABLE [ IF NOT EXISTS ] <replaceable class="PARAMETER">table_name</replaceable>
3131
PARTITION OF <replaceable class="PARAMETER">parent_table</replaceable> [ (
32-
{ <replaceable class="PARAMETER">column_name</replaceable> WITH OPTIONS [ <replaceable class="PARAMETER">column_constraint</replaceable> [ ... ] ]
32+
{ <replaceable class="PARAMETER">column_name</replaceable>[WITH OPTIONS ] [ <replaceable class="PARAMETER">column_constraint</replaceable> [ ... ] ]
3333
| <replaceable>table_constraint</replaceable> }
3434
[, ... ]
3535
) ] <replaceable class="PARAMETER">partition_bound_spec</replaceable>

‎doc/src/sgml/ref/create_table.sgml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXI
3535

3636
CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXISTS ] <replaceable class="PARAMETER">table_name</replaceable>
3737
OF <replaceable class="PARAMETER">type_name</replaceable> [ (
38-
{ <replaceable class="PARAMETER">column_name</replaceable> WITH OPTIONS [ <replaceable class="PARAMETER">column_constraint</replaceable> [ ... ] ]
38+
{ <replaceable class="PARAMETER">column_name</replaceable>[WITH OPTIONS ] [ <replaceable class="PARAMETER">column_constraint</replaceable> [ ... ] ]
3939
| <replaceable>table_constraint</replaceable> }
4040
[, ... ]
4141
) ]
@@ -46,7 +46,7 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXI
4646

4747
CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXISTS ] <replaceable class="PARAMETER">table_name</replaceable>
4848
PARTITION OF <replaceable class="PARAMETER">parent_table</replaceable> [ (
49-
{ <replaceable class="PARAMETER">column_name</replaceable> [ <replaceable class="PARAMETER">column_constraint</replaceable> [ ... ] ]
49+
{ <replaceable class="PARAMETER">column_name</replaceable> [WITH OPTIONS ] [<replaceable class="PARAMETER">column_constraint</replaceable> [ ... ] ]
5050
| <replaceable>table_constraint</replaceable> }
5151
[, ... ]
5252
) ] FOR VALUES <replaceable class="PARAMETER">partition_bound_spec</replaceable>

‎src/backend/parser/gram.y

Lines changed: 23 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -576,8 +576,6 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
576576
%type<str>part_strategy
577577
%type<partelem>part_elem
578578
%type<list>part_params
579-
%type<list>OptPartitionElementListPartitionElementList
580-
%type<node>PartitionElement
581579
%type<node>ForValues
582580
%type<node>partbound_datum
583581
%type<list>partbound_datum_list
@@ -3131,7 +3129,7 @@ CreateStmt:CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')'
31313129
$$ = (Node *)n;
31323130
}
31333131
|CREATEOptTempTABLEqualified_namePARTITIONOFqualified_name
3134-
OptPartitionElementListForValuesOptPartitionSpecOptWith
3132+
OptTypedTableElementListForValuesOptPartitionSpecOptWith
31353133
OnCommitOptionOptTableSpace
31363134
{
31373135
CreateStmt *n = makeNode(CreateStmt);
@@ -3150,7 +3148,7 @@ CreateStmt:CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')'
31503148
$$ = (Node *)n;
31513149
}
31523150
|CREATEOptTempTABLEIF_PNOTEXISTSqualified_namePARTITIONOF
3153-
qualified_nameOptPartitionElementListForValuesOptPartitionSpec
3151+
qualified_nameOptTypedTableElementListForValuesOptPartitionSpec
31543152
OptWithOnCommitOptionOptTableSpace
31553153
{
31563154
CreateStmt *n = makeNode(CreateStmt);
@@ -3213,11 +3211,6 @@ OptTypedTableElementList:
32133211
|/*EMPTY*/{$$ = NIL; }
32143212
;
32153213

3216-
OptPartitionElementList:
3217-
'('PartitionElementList')'{$$ =$2; }
3218-
|/*EMPTY*/{$$ = NIL; }
3219-
;
3220-
32213214
TableElementList:
32223215
TableElement
32233216
{
@@ -3240,17 +3233,6 @@ TypedTableElementList:
32403233
}
32413234
;
32423235

3243-
PartitionElementList:
3244-
PartitionElement
3245-
{
3246-
$$ = list_make1($1);
3247-
}
3248-
|PartitionElementList','PartitionElement
3249-
{
3250-
$$ = lappend($1,$3);
3251-
}
3252-
;
3253-
32543236
TableElement:
32553237
columnDef{$$ =$1; }
32563238
|TableLikeClause{$$ =$1; }
@@ -3262,28 +3244,6 @@ TypedTableElement:
32623244
|TableConstraint{$$ =$1; }
32633245
;
32643246

3265-
PartitionElement:
3266-
TableConstraint{$$ =$1; }
3267-
|ColIdColQualList
3268-
{
3269-
ColumnDef *n = makeNode(ColumnDef);
3270-
n->colname =$1;
3271-
n->typeName =NULL;
3272-
n->inhcount =0;
3273-
n->is_local =true;
3274-
n->is_not_null =false;
3275-
n->is_from_type =false;
3276-
n->storage =0;
3277-
n->raw_default =NULL;
3278-
n->cooked_default =NULL;
3279-
n->collOid = InvalidOid;
3280-
SplitColQualList($2, &n->constraints, &n->collClause,
3281-
yyscanner);
3282-
n->location =@1;
3283-
$$ = (Node *) n;
3284-
}
3285-
;
3286-
32873247
columnDef:ColIdTypenamecreate_generic_optionsColQualList
32883248
{
32893249
ColumnDef *n = makeNode(ColumnDef);
@@ -3305,7 +3265,25 @@ columnDef:ColId Typename create_generic_options ColQualList
33053265
}
33063266
;
33073267

3308-
columnOptions:ColIdWITHOPTIONSColQualList
3268+
columnOptions:ColIdColQualList
3269+
{
3270+
ColumnDef *n = makeNode(ColumnDef);
3271+
n->colname =$1;
3272+
n->typeName =NULL;
3273+
n->inhcount =0;
3274+
n->is_local =true;
3275+
n->is_not_null =false;
3276+
n->is_from_type =false;
3277+
n->storage =0;
3278+
n->raw_default =NULL;
3279+
n->cooked_default =NULL;
3280+
n->collOid = InvalidOid;
3281+
SplitColQualList($2, &n->constraints, &n->collClause,
3282+
yyscanner);
3283+
n->location =@1;
3284+
$$ = (Node *)n;
3285+
}
3286+
|ColIdWITHOPTIONSColQualList
33093287
{
33103288
ColumnDef *n = makeNode(ColumnDef);
33113289
n->colname =$1;
@@ -4872,7 +4850,7 @@ CreateForeignTableStmt:
48724850
$$ = (Node *) n;
48734851
}
48744852
|CREATEFOREIGNTABLEqualified_name
4875-
PARTITIONOFqualified_nameOptPartitionElementListForValues
4853+
PARTITIONOFqualified_nameOptTypedTableElementListForValues
48764854
SERVERnamecreate_generic_options
48774855
{
48784856
CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
@@ -4893,7 +4871,7 @@ CreateForeignTableStmt:
48934871
$$ = (Node *) n;
48944872
}
48954873
|CREATEFOREIGNTABLEIF_PNOTEXISTSqualified_name
4896-
PARTITIONOFqualified_nameOptPartitionElementListForValues
4874+
PARTITIONOFqualified_nameOptTypedTableElementListForValues
48974875
SERVERnamecreate_generic_options
48984876
{
48994877
CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);

‎src/bin/pg_dump/pg_dump.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15267,13 +15267,16 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
1526715267
continue;
1526815268
}
1526915269

15270-
/* Attribute type */
15271-
if ((tbinfo->reloftype || tbinfo->partitionOf) &&
15272-
!dopt->binary_upgrade)
15273-
{
15274-
appendPQExpBufferStr(q, " WITH OPTIONS");
15275-
}
15276-
else
15270+
/*
15271+
* Attribute type
15272+
*
15273+
* In binary-upgrade mode, we always include the type.
15274+
* If we aren't in binary-upgrade mode, then we skip the
15275+
* type when creating a typed table ('OF type_name') or a
15276+
* partition ('PARTITION OF'), since the type comes from
15277+
* the parent/partitioned table.
15278+
*/
15279+
if (dopt->binary_upgrade || (!tbinfo->reloftype && !tbinfo->partitionOf))
1527715280
{
1527815281
appendPQExpBuffer(q, " %s",
1527915282
tbinfo->atttypnames[j]);

‎src/test/regress/expected/create_table.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ SELECT conislocal, coninhcount FROM pg_constraint WHERE conrelid = 'part_b'::reg
624624
-- specify PARTITION BY for a partition
625625
CREATE TABLE fail_part_col_not_found PARTITION OF parted FOR VALUES IN ('c') PARTITION BY RANGE (c);
626626
ERROR: column "c" named in partition key does not exist
627-
CREATE TABLE part_c PARTITION OF parted FOR VALUES IN ('c') PARTITION BY RANGE ((b));
627+
CREATE TABLE part_c PARTITION OF parted(b WITH OPTIONS NOT NULL DEFAULT 0)FOR VALUES IN ('c') PARTITION BY RANGE ((b));
628628
-- create a level-2 partition
629629
CREATE TABLE part_c_1_10 PARTITION OF part_c FOR VALUES FROM (1) TO (10);
630630
-- Partition bound in describe output

‎src/test/regress/expected/sanity_check.out

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ onek|t
9393
onek2|t
9494
path_tbl|f
9595
person|f
96+
persons|f
97+
persons2|t
98+
persons3|t
9699
pg_aggregate|t
97100
pg_am|t
98101
pg_amop|t

‎src/test/regress/expected/typed_table.out

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
-- Clean up in case a prior regression run failed
2+
SET client_min_messages TO 'warning';
3+
DROP TYPE IF EXISTS person_type CASCADE;
4+
RESET client_min_messages;
15
CREATE TABLE ttable1 OF nothing;
26
ERROR: type "nothing" does not exist
37
CREATE TYPE person_type AS (id int, name text);
@@ -102,7 +106,32 @@ SELECT id, namelen(persons) FROM persons;
102106
1 | 4
103107
(1 row)
104108

105-
DROP TYPE person_type CASCADE;
106-
NOTICE: drop cascades to 2 other objects
107-
DETAIL: drop cascades to table persons
108-
drop cascades to function namelen(person_type)
109+
CREATE TABLE persons2 OF person_type (
110+
id WITH OPTIONS PRIMARY KEY,
111+
UNIQUE (name)
112+
);
113+
\d persons2
114+
Table "public.persons2"
115+
Column | Type | Collation | Nullable | Default
116+
--------+---------+-----------+----------+---------
117+
id | integer | | not null |
118+
name | text | | |
119+
Indexes:
120+
"persons2_pkey" PRIMARY KEY, btree (id)
121+
"persons2_name_key" UNIQUE CONSTRAINT, btree (name)
122+
Typed table of type: person_type
123+
124+
CREATE TABLE persons3 OF person_type (
125+
PRIMARY KEY (id),
126+
name NOT NULL DEFAULT ''
127+
);
128+
\d persons3
129+
Table "public.persons3"
130+
Column | Type | Collation | Nullable | Default
131+
--------+---------+-----------+----------+----------
132+
id | integer | | not null |
133+
name | text | | not null | ''::text
134+
Indexes:
135+
"persons3_pkey" PRIMARY KEY, btree (id)
136+
Typed table of type: person_type
137+

‎src/test/regress/sql/create_table.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ SELECT conislocal, coninhcount FROM pg_constraint WHERE conrelid = 'part_b'::reg
578578

579579
-- specify PARTITION BY for a partition
580580
CREATETABLEfail_part_col_not_found PARTITION OF parted FORVALUESIN ('c') PARTITION BY RANGE (c);
581-
CREATETABLEpart_c PARTITION OF parted FORVALUESIN ('c') PARTITION BY RANGE ((b));
581+
CREATETABLEpart_c PARTITION OF parted(b WITH OPTIONSNOT NULL DEFAULT0)FORVALUESIN ('c') PARTITION BY RANGE ((b));
582582

583583
-- create a level-2 partition
584584
CREATETABLEpart_c_1_10 PARTITION OF part_c FORVALUESFROM (1) TO (10);

‎src/test/regress/sql/typed_table.sql

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
-- Clean up in case a prior regression run failed
2+
SET client_min_messages TO'warning';
3+
4+
DROPTYPE IF EXISTS person_type CASCADE;
5+
6+
RESET client_min_messages;
7+
18
CREATETABLEttable1 OF nothing;
29

310
CREATETYPEperson_typeAS (idint, nametext);
@@ -60,4 +67,16 @@ INSERT INTO persons VALUES (1, 'test');
6067
CREATEFUNCTIONnamelen(person_type) RETURNSint LANGUAGE SQLAS $$SELECT length($1.name) $$;
6168
SELECT id, namelen(persons)FROM persons;
6269

63-
DROPTYPE person_type CASCADE;
70+
CREATETABLEpersons2 OF person_type (
71+
id WITH OPTIONSPRIMARY KEY,
72+
UNIQUE (name)
73+
);
74+
75+
\d persons2
76+
77+
CREATETABLEpersons3 OF person_type (
78+
PRIMARY KEY (id),
79+
nameNOT NULL DEFAULT''
80+
);
81+
82+
\d persons3

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp