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

Поиск
Список
Период
Сортировка
От Andrew Hammond
Тема using constraint based paritioning to fix EAV type schemas? (view inheritance and constraints)
Дата
Msg-id 1153238828.426611.113540@35g2000cwc.googlegroups.com
обсуждение исходный текст
Список 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(attribute3AS 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



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

Предыдущее
От: "Aaron Bono"
Дата:
Сообщение: Re: hi let me know the solution to this question
Следующее
От: Bricklen Anderson
Дата:
Сообщение: Re: hi let me know the solution to this question