I have:
create type thetype(width integer, height integer);
create table mytable(thetype thetype[]);
How can I make an insert statement, so if I add fields to the composite type in the future, the code/query doesn't break?
Maybe by specifying the fields of the composite type in the query?
This can be done for normal inserts (non arrays):
CREATE TABLE mytable (t thetype);
INSERT INTO mytable(t.width, t.height) VALUES (11,22);
(so when I add columns to the composite later, my old sql-insert doesn't break (not specified columns are inserted as NULL
)).
PS: I always query this data together. The other way is to use json but like this i have more flexibility (update an element of an composite type in an array, more data-types) and less storage (no keys saved for each row like in json/mongodb/hstore).