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
59407301
Commit
59407301
authored
Feb 16, 2017
by
Robert Haas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid crash in ALTER TABLE not_partitioned DETACH PARTITION.
Amit Langote, reviewed and slightly changed by me.
parent
93e6e405
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
14 deletions
+25
-14
src/backend/parser/parse_utilcmd.c
src/backend/parser/parse_utilcmd.c
+15
-14
src/test/regress/expected/alter_table.out
src/test/regress/expected/alter_table.out
+5
-0
src/test/regress/sql/alter_table.sql
src/test/regress/sql/alter_table.sql
+5
-0
No files found.
src/backend/parser/parse_utilcmd.c
View file @
59407301
...
...
@@ -133,7 +133,7 @@ static void transformConstraintAttrs(CreateStmtContext *cxt,
List
*
constraintList
);
static
void
transformColumnType
(
CreateStmtContext
*
cxt
,
ColumnDef
*
column
);
static
void
setSchemaName
(
char
*
context_schema
,
char
**
stmt_schema_name
);
static
void
transform
AttachPartition
(
CreateStmtContext
*
cxt
,
PartitionCmd
*
cmd
);
static
void
transform
PartitionCmd
(
CreateStmtContext
*
cxt
,
PartitionCmd
*
cmd
);
/*
...
...
@@ -2654,12 +2654,12 @@ transformAlterTableStmt(Oid relid, AlterTableStmt *stmt,
}
case
AT_AttachPartition
:
case
AT_DetachPartition
:
{
PartitionCmd
*
partcmd
=
(
PartitionCmd
*
)
cmd
->
def
;
transformAttachPartition
(
&
cxt
,
partcmd
);
/* assign transformed values */
transformPartitionCmd
(
&
cxt
,
partcmd
);
/* assign transformed value of the partition bound */
partcmd
->
bound
=
cxt
.
partbound
;
}
...
...
@@ -3032,26 +3032,27 @@ setSchemaName(char *context_schema, char **stmt_schema_name)
}
/*
* transformAttachPartition
* Analyze ATTACH PARTITION ... FOR VALUES ...
* transformPartitionCmd
* Analyze the ATTACH/DETACH PARTITION command
*
* In case of the ATTACH PARTITION command, cxt->partbound is set to the
* transformed value of cmd->bound.
*/
static
void
transform
AttachPartition
(
CreateStmtContext
*
cxt
,
PartitionCmd
*
cmd
)
transform
PartitionCmd
(
CreateStmtContext
*
cxt
,
PartitionCmd
*
cmd
)
{
Relation
parentRel
=
cxt
->
rel
;
/*
* We are going to try to validate the partition bound specification
* against the partition key of rel, so it better have one.
*/
/* the table must be partitioned */
if
(
parentRel
->
rd_rel
->
relkind
!=
RELKIND_PARTITIONED_TABLE
)
ereport
(
ERROR
,
(
errcode
(
ERRCODE_INVALID_OBJECT_DEFINITION
),
errmsg
(
"
\"
%s
\"
is not partitioned"
,
RelationGetRelationName
(
parentRel
))));
/* transform the
values
*/
/* transform the
partition bound, if any
*/
Assert
(
RelationGetPartitionKey
(
parentRel
)
!=
NULL
);
if
(
cmd
->
bound
!=
NULL
)
cxt
->
partbound
=
transformPartitionBound
(
cxt
->
pstate
,
parentRel
,
cmd
->
bound
);
}
...
...
src/test/regress/expected/alter_table.out
View file @
59407301
...
...
@@ -3259,6 +3259,11 @@ DETAIL: "list_parted2" is already a child of "list_parted2".
--
-- DETACH PARTITION
--
-- check that the table is partitioned at all
CREATE TABLE regular_table (a int);
ALTER TABLE regular_table DETACH PARTITION any_name;
ERROR: "regular_table" is not partitioned
DROP TABLE regular_table;
-- check that the partition being detached exists at all
ALTER TABLE list_parted2 DETACH PARTITION part_4;
ERROR: relation "part_4" does not exist
...
...
src/test/regress/sql/alter_table.sql
View file @
59407301
...
...
@@ -2139,6 +2139,11 @@ ALTER TABLE list_parted2 ATTACH PARTITION list_parted2 FOR VALUES IN (0);
-- DETACH PARTITION
--
-- check that the table is partitioned at all
CREATE
TABLE
regular_table
(
a
int
);
ALTER
TABLE
regular_table
DETACH
PARTITION
any_name
;
DROP
TABLE
regular_table
;
-- check that the partition being detached exists at all
ALTER
TABLE
list_parted2
DETACH
PARTITION
part_4
;
...
...
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