PostgreSQL 覆盖继承的列
假设我有一个 xmldoc 关系,如下所示:
Column | Type | Modifiers
--------------+-----------------------------+-----------------
docid | integer | not null
create_date | timestamp without time zone | not null
type | text | not null
xml | xml |
现在,假设我创建另一个表,该表仅继承自该表,没有任何其他列。比如说,我怎样才能将“xml”覆盖为“文本”类型?
目前,我得到:
ERROR: cannot alter inherited column "xml"
那么,数据库继承中的重写是如何工作的? [具体来说,我使用的是 PostgreSQL 8.3]
Suppose I have an xmldoc relation which is as follows:
Column | Type | Modifiers
--------------+-----------------------------+-----------------
docid | integer | not null
create_date | timestamp without time zone | not null
type | text | not null
xml | xml |
Now, let's say I create another table which just inherits from this table without any other columns. How can I, say, override 'xml' to be of type 'text'?
Currently, I'm getting :
ERROR: cannot alter inherited column "xml"
So, how does overriding in DB inheritance work? [Specifically, I'm using PostgreSQL 8.3]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自精细手册:
因此,您不能将
xml
重写为text
类型。至于“数据库继承中的重写如何工作?”是的,事实并非如此,您不能通过像这样的继承来改变接口(即列),您只能添加新的东西或收紧约束。您熟悉里氏替换原则吗?更改列类型会使表的公共属性(又称接口)不兼容。
From the fine manual:
So you cannot override
xml
to be of typetext
. And as far as "how does overriding in DB inheritance work?" goes, it doesn't, you can't alter the interface (i.e. columns) through inheritance like that, you can only add new things or tighten constraints.Are you familiar with Liskov substitution principle? Changing the column type would make the tables's common properties (AKA interfaces) incompatible.