Skip site navigation (1) Skip section navigation (2)

Re: [GENERAL] Postgresql 8.3X supports Arrays of Composite Types?

From: David Fetter <david(at)fetter(dot)org>
To: Robson Fidalgo <rdnf(at)cin(dot)ufpe(dot)br>
Cc: pgsql-docs(at)postgresql(dot)org, pgsql-general(at)postgresql(dot)org
Subject: Re: [GENERAL] Postgresql 8.3X supports Arrays of Composite Types?
Date: 2009-04-19 23:56:19
Message-ID: 20090419235619.GB10700@fetter.org (view raw or flat)
Thread:
Lists: pgsql-docspgsql-general
On Sun, Apr 19, 2009 at 06:03:26PM -0300, Robson Fidalgo wrote:
> Hello,
> I am using postgresql 8.3X and I created a table (see example below)
> that has an attribute that is an Array of a Composite Type (ROW).
> However, I do not know how can I insert a record in this table.

You want a normalized table anyhow.  If you want something
denormalized, use a view.

> Example:
> 
> CREATE table phone (
>   cod varchar,
>   num varchar);
> 
> CREATE TABLE person (
>   name varchar,
>   telephone phone[]);

This is better as:

CREATE TABLE phone (
    cod VARCHAR,
    num VARCHAR,
    PRIMARY KEY(cod, num)
);

CREATE TABLE person (
    name varchar,
    PRIMARY KEY(name)
)

CREATE TABLE person_phone (
    name VARCHAR NOT NULL REFERENCES person(name),
    cod VARCHAR,
    num VARCHAR,
    FOREIGN KEY(cod, num) REFERENCES phone(cod, num),
    PRIMARY KEY(name, cod, num)
);

Cheers,
David.
-- 
David Fetter <david(at)fetter(dot)org> http://fetter.org/
Phone: +1 415 235 3778  AIM: dfetter666  Yahoo!: dfetter
Skype: davidfetter      XMPP: david(dot)fetter(at)gmail(dot)com

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate

In response to

Responses

pgsql-docs by date

Next:From: ali haghighatDate: 2009-04-20 07:49:20
Subject: role hierarchy
Previous:From: Tom LaneDate: 2009-04-19 23:25:32
Subject: Re: [GENERAL] Postgresql 8.3X supports Arrays of Composite Types?

pgsql-general by date

Next:From: Net Tree Inc.Date: 2009-04-20 02:10:08
Subject: Frequently unable connecting to db "server doesn't listen"
Previous:From: Tom LaneDate: 2009-04-19 23:25:32
Subject: Re: [GENERAL] Postgresql 8.3X supports Arrays of Composite Types?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group