[英]How to add a column to typed table without altering type in PostgreSQL?
我正在使用PostgreSQL 9.5,我有一个TYPE,它描述了一组列:
CREATE TYPE datastore.record AS
(recordid bigint,
...
tags text[]);
我在这个TYPE上创建了许多表:
CREATE TABLE datastore.events
OF datastore.record;
现在我想在一个表中添加一个列,该表依赖于此TYPE而不更新TYPE。 我认为这是不可能的,因此我想知道是否有办法从这个TYPE取消绑定我的表而不丢失任何数据或将表复制到临时表中?
有一个特殊选项not of
为此目的。 根据文件 :
NOT OF - 此表单将类型表与其类型分开。
所以:
alter table my_table not of;
alter table my_table add new_column integer;
如果你不想破坏关系:
--drop table if exists t2;
--drop table if exists t1;
--drop type if exists tp_foo;
create type tp_foo as (i int, x int);
create table t1 of tp_foo;
create table t2 (y text) inherits(t1);
alter type tp_foo add attribute z date cascade;
select * from t2;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.