Skip to content

Commit 4a0a0d8

Browse files
committed
Fix column type change on plain tables
A recent change blocked changing types of space-partitioned hypertable columns. However, this blocking should not apply to regular tables, which otherwise causes a crash. This change fixes this issue by properly checking that the the table is a hypertable.
1 parent cf009cc commit 4a0a0d8

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

src/process_utility.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,7 @@ process_altertable_end_index(Node *parsetree, CollectedCommand *cmd)
10741074
}
10751075

10761076
static void
1077-
process_altertable_start(Node *parsetree)
1077+
process_altertable_start_table(Node *parsetree)
10781078
{
10791079
AlterTableStmt *stmt = (AlterTableStmt *) parsetree;
10801080
Oid relid = AlterTableLookupRelation(stmt, NoLock);
@@ -1122,7 +1122,9 @@ process_altertable_start(Node *parsetree)
11221122
break;
11231123
case AT_AlterColumnType:
11241124
Assert(IsA(cmd->def, ColumnDef));
1125-
process_alter_column_type_start(ht, cmd);
1125+
1126+
if (ht != NULL)
1127+
process_alter_column_type_start(ht, cmd);
11261128
break;
11271129
default:
11281130
break;
@@ -1132,6 +1134,21 @@ process_altertable_start(Node *parsetree)
11321134
cache_release(hcache);
11331135
}
11341136

1137+
static void
1138+
process_altertable_start(Node *parsetree)
1139+
{
1140+
AlterTableStmt *stmt = (AlterTableStmt *) parsetree;
1141+
1142+
switch (stmt->relkind)
1143+
{
1144+
case OBJECT_TABLE:
1145+
process_altertable_start_table(parsetree);
1146+
break;
1147+
default:
1148+
break;
1149+
}
1150+
}
1151+
11351152
static void
11361153
process_altertable_end_subcmd(Hypertable *ht, Node *parsetree, ObjectAddress *obj)
11371154
{
@@ -1271,7 +1288,6 @@ process_altertable_end(Node *parsetree, CollectedCommand *cmd)
12711288
}
12721289
}
12731290

1274-
12751291
static void
12761292
create_trigger_chunk(Hypertable *ht, Oid chunk_relid, void *arg)
12771293
{

test/expected/plain.out

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ CREATE TABLE regular_table(time timestamp, temp float8, tag text, color integer)
66
-- Renaming indexes should work
77
CREATE INDEX time_color_idx ON regular_table(time, color);
88
ALTER INDEX time_color_idx RENAME TO time_color_idx2;
9+
ALTER TABLE regular_table ALTER COLUMN color TYPE bigint;
910
\d+ regular_table
1011
Table "public.regular_table"
1112
Column | Type | Modifiers | Storage | Stats target | Description
1213
--------+-----------------------------+-----------+----------+--------------+-------------
1314
time | timestamp without time zone | | plain | |
1415
temp | double precision | | plain | |
1516
tag | text | | extended | |
16-
color | integer | | plain | |
17+
color | bigint | | plain | |
1718
Indexes:
1819
"time_color_idx2" btree ("time", color)
1920

test/sql/plain.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ CREATE TABLE regular_table(time timestamp, temp float8, tag text, color integer)
88
-- Renaming indexes should work
99
CREATE INDEX time_color_idx ON regular_table(time, color);
1010
ALTER INDEX time_color_idx RENAME TO time_color_idx2;
11+
ALTER TABLE regular_table ALTER COLUMN color TYPE bigint;
1112

1213
\d+ regular_table
1314

0 commit comments

Comments
 (0)