using constraint based paritioning to fix EAV type schemas? (view inheritance and constraints)

From: "Andrew Hammond" <andrew(dot)george(dot)hammond(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org pgsql-sql(at)postgresql(dot)org
Subject: using constraint based paritioning to fix EAV type schemas? (view inheritance and constraints)
Date: 2006-07-18 16:07:08
Message-ID: 1153238828.426611.113540@35g2000cwc.googlegroups.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-sql

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

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Chris Browne 2006-07-18 16:10:00 gBorg misbehaviour
Previous Message Andrew Dunstan 2006-07-18 16:04:49 Re: [PATCHES] Proposed patch for contrib/cube

Browse pgsql-sql by date

  From Date Subject
Next Message Bricklen Anderson 2006-07-18 16:44:50 Re: hi let me know the solution to this question
Previous Message Aaron Bono 2006-07-18 15:54:12 Re: hi let me know the solution to this question