DEFAULT Constraint based on table type? - Mailing list pgsql-sql

From Announce
Subject DEFAULT Constraint based on table type?
Date
Msg-id KBEKKNMFLELKGIADDEPEMEBPCDAA.truthhurts@insightbb.com
Whole thread Raw
In response to Re: idea for a geographically distributed database: how best to implement?  (Andy Ballingall <andy@areyoulocal.co.uk>)
Responses Re: DEFAULT Constraint based on table type?
Re: DEFAULT Constraint based on table type?
Re: DEFAULT Constraint based on table type?
List pgsql-sql
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



pgsql-sql by date:

Previous
From: Frank Bax
Date:
Subject: Re: Anual Query
Next
From: Jaime Casanova
Date:
Subject: Re: DEFAULT Constraint based on table type?