Can we add column to typed table in PostgreSql?

Viewed 111

Created a type vehicle as-

create type vehicle as ( tag text, name text);

Create table using type as-

create table bike of vehicle;

Trying to add column as-

alter table bike add column attributes text;
ERROR:  cannot add column to typed table

Is it possible to add column in typed column by any method?

1 Answers

From the documentation for ALTER TYPE

CASCADE
Automatically propagate the operation to typed tables of the type being altered, and their descendants.

So, using your example:

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

results in:

|tag|name|test|
|---|----|----|
|t  |n   |    |
Related