Re: Altering array(composite-types) without breaking code when inserting them and similar questions

From: David G Johnston <david(dot)g(dot)johnston(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Altering array(composite-types) without breaking code when inserting them and similar questions
Date: 2014-04-20 17:30:18
Message-ID: 1398015018621-5800848.post@n5.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Dorian Hoxha wrote
> Hi list,
>
> I have a
> create type thetype(width integer, height integer);
> create table mytable(thetype thetype[]);
>
> How can i make an insert statement so if i later add fields to the
> composite type, 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);
>
>
> Also how to update an whole element of an array of composites ?
> Also, how to update an attribute in a specific element in an array of
> composites?
>
> (so when i add columns later to the composite, my old code doesn't break)
>
> How much overhead have the composite types beside the values and nulls?
>
> Thanks

You should probably just use a table...

I'm doubtful you can alter the type without breaking code.

You can replace a entire single array element as described in the
documentation. You cannot update single attributes.

As to the overhead question what are you comparing against and what do you
want to measure?

David J.

--
View this message in context: http://postgresql.1045698.n5.nabble.com/Altering-array-composite-types-without-breaking-code-when-inserting-them-and-similar-questions-tp5800847p5800848.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Fede Martinez 2014-04-20 17:54:29 Re: Altering array(composite-types) without breaking code when inserting them and similar questions
Previous Message Dorian Hoxha 2014-04-20 17:02:10 Altering array(composite-types) without breaking code when inserting them and similar questions