pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andrew G. Hammond <drew@xyzzy.dhs.org>
To: Jyoti Patil <Jyoti@ionit.co.uk>
To: 'pgsql-admin@postgresql.org' <pgsql-admin@postgresql.org>
Subject: Re: Creating schema in postgres
Date: Wed, 28 Nov 2001 11:39:44 -0500
Message-ID: <E1697kR-0001se-00@xyzzy.lan.internal> (raw)
In-Reply-To: <3316C8A04DC3D2119CF10090273A9558B3C7C7@EMAIL>
References: <3316C8A04DC3D2119CF10090273A9558B3C7C7@EMAIL>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 2001 November 28 05:35 am, Jyoti Patil wrote:
> I would like to know how can we create a schema in postgres.

There are graphical front end tools available that will do this for you, but 
it all comes down to CREATE statements in SQL.  You can communicate dirrectly 
with the database (in SQL) using the psql command line utility that comes 
with the database.  To create a schema (in psql), you might do something like 
the following:

- -- table to list people
CREATE TABLE person (id SERIAL PRIMARY KEY,
  given_name TEXT NOT NULL,
  surname TEXT NOT NULL,
  birth_date DATE CHECK (birth_date > 1960-01-01),  -- no old people allowed
  eye_colour TEXT );

- -- table to list friendships ( n to m relationship of person to person)
CREATE TABLE friend (id SERIAL PRIMARY KEY,
  person_a INTEGER REFERENCES person(id),
  person_b INTEGER REFERENCES person(id) );

- -- pets ( 1 to n relationship of people to pets)
CREATE TABLE pet (id SERIAL PRIMARY KEY,
  name TEXT NOT NULL,
  type TEXT NOT NULL CHECK (type IN ('cat', 'dog', 'bird', 'llama')),
  owner INTEGER REFERENCES person(id) );

And, to increase the performance of sorts and selects, create some indices on 
the above tables:

CREATE INDEX p_a_idx ON person (given_name, surname);
CREATE INDEX p_b_idx ON person (surname, given_name);
CREATE INDEX f_a_idx ON friend (person_a);
CREATE INDEX f_b_idx ON friend (person_b);
CREATE INDEX pet_owner_idx ON pet(owner);

Anyway, I hope this is enough to get you pointed in the right dirrection.  
Feel free to ask me for more details.

- -- 
Andrew G. Hammond     mailto:drew@xyzzy.dhs.org   http://xyzzy.dhs.org/~drew/
56 2A 54 EF 19 C0 3B 43 72 69 5B E3 69 5B A1 1F                  613-389-5481
5CD3 62B0 254B DEB1 86E0  8959 093E F70A B457 84B1
"To blow recursion you must first blow recur" -- me
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iEYEARECAAYFAjwFE1AACgkQCT73CrRXhLGQhACfZPFhzCDoODJh/fdL7e36uozP
iL4An1WmIo6bm1Bysu7WHbpQQUZ1gM0w
=vFbY
-----END PGP SIGNATURE-----



view thread (3+ messages)

Message-ID: <E1697kR-0001se-00@xyzzy.lan.internal>
Permalink:  ../E1697kR-0001se-00@xyzzy.lan.internal/
Also on:    postgresql.org/message-id/E1697kR-0001se-00@xyzzy.lan.internal

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: drew@xyzzy.dhs.org, Jyoti@ionit.co.uk
  Subject: Re: Creating schema in postgres
  In-Reply-To: <E1697kR-0001se-00@xyzzy.lan.internal>
  References: <3316C8A04DC3D2119CF10090273A9558B3C7C7@EMAIL> <E1697kR-0001se-00@xyzzy.lan.internal>

* 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