inheritance and partial index: how to override constraints or default_values

From: Nico <nicod(at)tiscalinet(dot)it>
To: pgsql-general(at)postgresql(dot)org
Cc: chris(at)bitmead(dot)com, Oliver(dot)Elphick(at)lfix(dot)co(dot)uk, Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
Subject: inheritance and partial index: how to override constraints or default_values
Date: 2001-02-27 14:13:20
Message-ID: 01022712153500.02035@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I want to partial index every table in a inherited tree.
Please let me know how to override the fields along inheritance?

===8<=============
CREATE SEQUENCE "a_id_seq" increment 1 minvalue 0100000000 maxvalue
0199999999 start 0100000001 cache 1;
CREATE TABLE "a" (
"id" int4 DEFAULT nextval('a_id_seq'::text) UNIQUE NOT NULL,
"info_a" text,
"created" timestamp DEFAULT CURRENT_TIMESTAMP
);
SELECT * from "a";

CREATE SEQUENCE "b_id_seq" increment 1 minvalue 0200000000 maxvalue
0299999999 start 0200000001 cache 1;
CREATE TABLE "b" (
"id" int4 DEFAULT nextval('b_id_seq'::text) UNIQUE NOT NULL,
"info_b" text
) inherits ("a");
SELECT * from "b";

================
psql 7.1beta5 output:

CREATE
psql:test.sql:13: NOTICE: CREATE TABLE/UNIQUE will create implicit index
'a_id_key' for table 'a'
CREATE
id | info_a | created
----+--------+---------
(0 rows)

CREATE
psql:test.sql:20: NOTICE: CREATE TABLE/UNIQUE will create implicit index
'b_id_key' for table 'b'
psql:test.sql:20: ERROR: CREATE TABLE: attribute "id" already exists in
inherited schema
psql:test.sql:21: ERROR: Relation 'b' does not exist
======8<=============

A note for developers: along inheritance if there are two identical attribute
names, IMHO, pg should use the last definition, rather than complaining.
Or better, pg should check if they are of the same type, but however should
always use the last constraint/default_value definition! (I am talking about
father-son inheritance, and not multiple inheritance, where the attribute
name conflict should be dealed separately)

regards, nico

Browse pgsql-general by date

  From Date Subject
Next Message Gunnar R|nning 2001-02-27 14:22:48 Re: Can PostgreSQL be a mail backend?
Previous Message Marc SCHAEFER 2001-02-27 14:13:17 Re: Re: Slowdown problem when writing 1.7million records