X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id B60209DD6CC for ; Mon, 28 Nov 2005 17:21:02 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 46414-02-9 for ; Mon, 28 Nov 2005 17:20:58 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sccimhc91.asp.att.net (sccimhc91.asp.att.net [63.240.76.165]) by postgresql.org (Postfix) with ESMTP id 70CA09DD6B5 for ; Mon, 28 Nov 2005 16:22:25 -0400 (AST) Received: from krunk (12-221-107-222.client.insightbb.com[12.221.107.222]) by sccimhc91.asp.att.net (sccimhc91) with SMTP id <20051128202226i9100lflg2e>; Mon, 28 Nov 2005 20:22:26 +0000 From: "Announce" To: Subject: DEFAULT Constraint based on table type? Date: Mon, 28 Nov 2005 14:22:49 -0600 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="windows-1250" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2910.0) Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 In-Reply-To: X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200511/262 X-Sequence-Number: 23513 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