[SQL] Primary and Foreign Key?

2005-09-22 Thread Announce
I have the following related tables:

PEOPLE
--
peopleid pkey,
name,
etc


GROUPS
-
groupid pkey,
description,
etc


PEOPLEGROUPS
---
peopleid pkey/fkey,
groupid pkey/fkey


What is the CORRECT way (in Postgres) to define the PEOPLEGROUPS table so
that it has both the double primary key AND still acts as a foreign key for
people.peopleid and groups.groupid? Can i specify both or is this not
necessary? Any suggestions would be appreciated.

Thanks!

--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.344 / Virus Database: 267.11.4/109 - Release Date: 9/21/2005


---(end of broadcast)---
TIP 3: Have you checked our extensive FAQ?

   http://www.postgresql.org/docs/faq


[SQL] DEFAULT Constraint based on table type?

2005-11-28 Thread Announce
Lets say I have the following tables.

CREATE TABLE animals(id primary key, name varchar, type varchar);
CREATE TABLE dogs (breed varchar)INHERITS (animals);
CREATE TABLE birds (bool hasFeathers) INHERITS (animals);

Is there a way I can specify a default on the child table that will populate
the 'type' column? For example, if I am inserting a row in table DOGS, I
would always want the default value for column TYPE to be 'DOG'. If I am
inserting into BIRDS type 'BIRD'.

I know that I could add individual triggers on each table that set the TYPE
field to a default value on insert but I wanted a more simple solution like
setting a DEFAULT table-constraint.

Also, In java, this could be done on a parent object by overriding a
constructor or method, using the Class object or instanceof.  Is there
anyway for a table to "know" it's "class" in this scenario?

Thanks,

-Aaron


---(end of broadcast)---
TIP 5: don't forget to increase your free space map settings