Re: how to add array of objects to a record

Поиск
Список
Период
Сортировка
От Joris Dobbelsteen
Тема Re: how to add array of objects to a record
Дата
Msg-id E4953B65D9E5054AA6C227B410C56AA9C311@exchange1.joris2k.local
обсуждение исходный текст
Ответ на how to add array of objects to a record  ("dfx" <dfx@dfx.it>)
Ответы R: how to add array of objects to a record
Список pgsql-general
>-----Original Message-----
>From: pgsql-general-owner@postgresql.org
>[mailto:pgsql-general-owner@postgresql.org] On Behalf Of dfx
>Sent: Sunday, 3 February 2008 10:38
>To: pgsql-general@postgresql.org
>Subject: [GENERAL] how to add array of objects to a record
>
>Hi list,
>
>Can I add an array of object to a record?
>
>For example if I have a class (or type) phone_number:
>
>create type phone_number as(
>name char(20),
>caption char(50),
>ph_num char(25));
>
>and I would like associate several (unknown number, a priori)
>phone numbers to a record "persons"
>can I create a table like this:
>
>create table persons(
>id integer,
>first_name char(50),
>family_name char(50),
>phone_numbers phone_number[])
>
>and how I have to write the insert and the select queries to
>put and get the array of phone numbers?

Its an SQL database, do not fall back to paradigms from imperative
programming languages (like C, Java, PHP, Perl, ...). Postgres is an
implementation of the relational model, which works very nice on sets.
It does not have a good concept of pointers and alike (they can be
represented, but inefficiently).

Transform you type into a table and add an "id" attribute that
references the persons table (using a foreign key). At this point you
can use regular SQL statements.

- Joris


В списке pgsql-general по дате отправления:

Предыдущее
От: "dfx"
Дата:
Сообщение: how to add array of objects to a record
Следующее
От: vladimir konrad
Дата:
Сообщение: Re: [OT] "advanced" database design (long)