X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 4446A9FB1E2; Tue, 18 Jul 2006 13:33:05 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 50733-03-3; Tue, 18 Jul 2006 13:32:53 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- X-Greylist: from auto-whitelisted by SQLgrey- Received: from floppy.pyrenet.fr (floppy.pyrenet.fr [194.116.145.2]) by postgresql.org (Postfix) with ESMTP id 2A1479FA004; Tue, 18 Jul 2006 13:07:17 -0300 (ADT) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id E622030949; Tue, 18 Jul 2006 18:07:14 +0200 (MET DST) From: "Andrew Hammond" X-Newsgroups: pgsql.sql,pgsql.hackers Subject: using constraint based paritioning to fix EAV type schemas? (view inheritance and constraints) Date: 18 Jul 2006 09:07:08 -0700 Organization: http://groups.google.com Lines: 54 Message-ID: <1153238828.426611.113540@35g2000cwc.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Complaints-To: groups-abuse@google.com User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.4) Gecko/20060608 Ubuntu/dapper-security Firefox/1.5.0.4,gzip(gfe),gzip(gfe) X-HTTP-Via: 1.1 choppr01:3128 (Squid/2.4.STABLE7) Complaints-To: groups-abuse@google.com Injection-Info: 35g2000cwc.googlegroups.com; posting-host=207.35.222.39; posting-account=cSUlcA0AAABWACaPjo2Z9C0GBLTio512 To: pgsql-hackers@postgresql.org pgsql-sql@postgresql.org X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200607/231 X-Sequence-Number: 25805 I have a client with the following EAV inspired schema. CREATE TABLE many_tables ( table_id text primary key, -- defines which virtual table is encoded attribute1 text, attribute2 text, attribute3 text, attribute4 text, ... ); I'd like to use a mix of constraint based paritioning, rules _and_views_ to implement a real schema underneath this mess, like the following. CREATE TABLE cat ( cat_id INTEGER PRIMARY KEY, cat_name TEXT NOT NULL, aloofness NUMERIC(1,3) DEFAULT 1.0 CHECK (0.0 <= aloofness AND aloofness <= 1.0) ); CREATE RULE many_tables_cat_insert AS ON INSERT TO many_tables WHERE table_id = 'cat' DO INSTEAD INSERT INTO cat (cat_id, cat_name, aloofness) VALUES ( CAST(attribute1 AS integer), attribute2, CAST(attribute3 AS numeric(1,3)) -- gleefully ignore the other attributes ); -- etc for UPDATE, and DELETE rules -- This part doesn't work CREATE VIEW many_tables_a (CHECK (table_id = 'cat')) INHERITS (many_tables) AS SELECT 'cat' AS table_id, CAST(cat_id AS text) AS attribute1, cat_name AS attribute2, CAST(aloofness AS text) AS attribute3, null AS attribute4, ... FROM cat; So, I guess I'm stuck doing the UNION ALL approach in this instance. This won't get me the partitioning win, nor the flexibility and cleanliness of design that I'd get with inheritance. As far as I can see, supporting the above would it mean adding inheritance and constraint support to views. Does anyone have a better approach? Drew