我们可以在PostgreSql中向类型化表添加列吗?
创建了一个类型车辆作为-我们可以在PostgreSql中向类型化表添加列吗?,sql,postgresql,Sql,Postgresql,创建了一个类型车辆作为- create type vehicle as ( tag text, name text); 使用类型作为创建表- create table bike of vehicle; 正在尝试将列添加为- alter table bike add column attributes text; ERROR: cannot add column to typed table 是否可以通过任何方法在类型化列中添加列?来自的文档 级联 自动将操作传播到正在更改的类型的类型表及
create type vehicle as ( tag text, name text);
使用类型作为创建表-
create table bike of vehicle;
正在尝试将列添加为-
alter table bike add column attributes text;
ERROR: cannot add column to typed table
是否可以通过任何方法在类型化列中添加列?来自的文档
级联
自动将操作传播到正在更改的类型的类型表及其后代 因此,以你的例子:
CREATE TYPE vehicle AS ( tag text, name text);
CREATE TABLE bike OF vehicle;
INSERT INTO bike(tag, name) values ('t','n')
ALTER TYPE vehicle ADD ATTRIBUTE test text CASCADE;
SELECT * FROM bike
结果:
|tag|name|test|
|---|----|----|
|t |n | |