pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Huxton <dev@archonet.com>
To: xchris <lyralyra@fastmail.fm>
Cc: pgsql-sql@postgresql.org
Subject: Re: Noob question about types and lists
Date: Thu, 06 Oct 2005 12:20:46 +0100
Message-ID: <4345088E.4090001@archonet.com> (raw)
In-Reply-To: <1128595206.27646.18.camel@lyra>
References: <1128595206.27646.18.camel@lyra>

xchris wrote:
> CREATE TYPE address AS
> (
>         street          VARCHAR(160),
>         city            INTEGER,
>         cap             INTEGER,
>         country         INTEGER  (those are referring to other table)
> );
> 
> and then composing table client
> 
> CREATE TABLE client
> (
>         id              SERIAL PRIMARY KEY,
>         name            VARCHAR(80),
>         surname         VARCHAR(80),
>         address         address[3]
> 	....
>         UNIQUE (name,surname)
> );
> 
> 
> This doesn't work.
> I cannot create a list of types.
> 
> I'm using a wrong syntax? or simply i cannot do this?

 From the manuals...

8.10. Arrays
PostgreSQL allows columns of a table to be defined as variable-length 
multidimensional arrays. Arrays of any built-in or user-defined base 
type can be created. (Arrays of composite types or domains are not yet 
supported, however.)

So - you can't do this at the moment.

However - I don't think you want to anyway. If you're going to use a 
relational database, try a relational approach! Typically, you would do 
something like:

CREATE TABLE client  (id ..., name ...)
CREATE TABLE address (id ..., street ...)
CREATE TABLE client_address (client_id ..., address_id ...)

Then, you can add some foreign-key constraints so PG makes sure that the 
ID numbers in client_address are all valid.

This makes it simple to get client names, client addresses or both together.

HTH
--
   Richard Huxton
   Archonet Ltd



view thread (4+ messages)  latest in thread

Message-ID: <4345088E.4090001@archonet.com>
Permalink:  ../4345088E.4090001@archonet.com/
Also on:    postgresql.org/message-id/4345088E.4090001@archonet.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: dev@archonet.com, lyralyra@fastmail.fm
  Subject: Re: Noob question about types and lists
  In-Reply-To: <4345088E.4090001@archonet.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox