postgresql - 无法更改列以更改数据类型,因为继承了列
问题描述
我创建了一个名为的表trackings
和许多分区子表,它们被命名为trackings_pt_...
.
分区表trackings_pt_...
继承自该trackings
表。
我想将id
所有这些(父表和子表)的列从integer
更改为bigint
.
Alter table trackings alter column id set data type bigint;
我面临
ERROR: cannot alter inherited column "id"
请帮我解决它。
Postgres 版本:x86_64-apple-darwin17.7.0 上的 PostgreSQL 11.2,由 Apple LLVM 版本 10.0.0 (clang-1000.11.45.5) 编译,64 位
解决方案
您必须尝试更改子表上的数据类型,因为它适用于父表:
CREATE TABLE inh_parent (id integer NOT NULL, val text NOT NULL);
CREATE TABLE inh_child () INHERITS (inh_parent);
CREATE TABLE inh_child2 (id integer NOT NULL) INHERITS (inh_parent);
NOTICE: merging column "id" with inherited definition
ALTER TABLE inh_parent ALTER id TYPE bigint; -- works
ALTER TABLE inh_child ALTER id TYPE int; -- fails
ERROR: cannot alter inherited column "id"
trackings
必须从另一个表继承。跑\d trackings
进去psql
看看。
推荐阅读
- python - 如何在 python 中使用 pyinstaller 插入或包含包?
- python-3.x - 在 Python 中快速操作嵌套循环
- asp.net-web-api - .Net Core 中的 Kafka 消费者
- python - Pandas - 绘制两个数据框 - 具有共同的图例
- azure - 我希望来自 Web 应用程序的响应应该只通过应用程序网关
- azure-cosmosdb - Cosmos DB 中归档数据的最佳实践
- android - Android Studio3.5突然无法解析符号
- applescript - 有没有办法使用 ApplescriptObjc 解码 Quoted-Printable 编码?
- php - 如何通过生成列布局在 foreach 中输出元素?
- mongodb - 带有 C# 驱动程序的 MongoDB - 带有排序的日期格式