Re: DEFAULT Constraint based on table type?

Поиск
Список
Период
Сортировка
От Oliver Elphick
Тема Re: DEFAULT Constraint based on table type?
Дата
Msg-id 1133260318.10517.34.camel@linda.lfix.co.uk
обсуждение исходный текст
Ответ на DEFAULT Constraint based on table type?  ("Announce" <truthhurts@insightbb.com>)
Ответы Re: DEFAULT Constraint based on table type?  (Oliver Elphick <olly@lfix.co.uk>)
Список pgsql-sql
On Mon, 2005-11-28 at 14:22 -0600, Announce wrote:
> 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?

SELECT tableoid::regproc, * from animals;

-- 
Oliver Elphick                                          olly@lfix.co.uk
Isle of Wight                              http://www.lfix.co.uk/oliver
GPG: 1024D/A54310EA  92C8 39E7 280E 3631 3F0E  1EC0 5664 7A2F A543 10EA
======================================== Do you want to know God?   http://www.lfix.co.uk/knowing_god.html
 



В списке pgsql-sql по дате отправления:

Предыдущее
От: Bruno Wolff III
Дата:
Сообщение: Re: join if all matches
Следующее
От: Oliver Elphick
Дата:
Сообщение: Re: DEFAULT Constraint based on table type?