Altering array(composite-types) without breaking code when inserting them

From: Dorian Hoxha <dorian(dot)hoxha(at)gmail(dot)com>
To: psycopg(at)postgresql(dot)org
Subject: Altering array(composite-types) without breaking code when inserting them
Date: 2014-04-27 11:03:21
Message-ID: CANsFX07yvsP3NqeED8w21ytu7nuTC7HRXgd7BU6J=3kjUrQ-5g@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: psycopg

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).

Browse psycopg by date

  From Date Subject
Next Message Nicolas Boullis 2014-04-28 08:47:45 Re: Problem with ZPsycopgDA’s pool
Previous Message Nicolas Boullis 2014-04-17 22:12:00 Re: Problem with ZPsycopgDA’s pool