Обсуждение: Composite Type : pros and cons

Поиск
Список
Период
Сортировка

Composite Type : pros and cons

От
Leguevaques Alex
Дата:
Hello,
I'm new to Pg and exploring its advanced functionalities for a project.
I find composite type very interesting, but what are problems/limitations ?
I'd want to create this structure for example: 
Phone
Nom du champ
Type 
Accès
Clef
Commentaire
typ_tel
integer


type téléphone (liste  25)
tel_pre
varchar(5)


Préfixe international téléphone
tel_num
varchar(14)



tel_ext
varchar(5)


Numéro de poste

and other structures for address and timestamp fields (creation and update timestamps.

Is it a good idea ? Are index, constraints possible/easy on subfields ?

Thank you

Re: Composite Type : pros and cons

От
Merlin Moncure
Дата:
On Thu, Jan 26, 2012 at 3:22 AM, Leguevaques Alex
<alex.leguevaques@wanadoo.fr> wrote:
>
> Hello,
> I'm new to Pg and exploring its advanced functionalities for a project.
> I find composite type very interesting, but what are problems/limitations ?
> I'd want to create this structure for example:

Composite types add a little value in that you can apply frequently
grouped together fields in a table.  This can save a little typing.
The downside is you are diverging from classic sql mechanics a little
bit which can make some things awkward.

Where they really shine though is as variables if you are doing a lot
of backend programming with functions.  You can pass them too and from
functions and make arrays out of them...this is very powerful once you
get the hang of it.

If you are using a client stack that understands postgres composite
types, you can (ab)use this to send complicated datasets to and from
the database.

merlin