From: | Mohd Toha Taifor <mtzza(at)yahoo(dot)com> |
---|---|
To: | pgsql-admin(at)postgresql(dot)org |
Subject: | Dynamic columns |
Date: | 2002-01-23 03:53:37 |
Message-ID: | 20020123035337.66997.qmail@web13807.mail.yahoo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-admin |
in term of performance, which is better?
i want to create dynamic columns for the same items:
-- items to be created
create table items (
id integer
primary key,
name varchar(100)
);
-- categorization for items
create table categories (
id integer
primary key,
name varchar(100)
);
create table item_category_map (
item_id integer
references items
on delete cascade,
category_id integer
references categories
on delete cascade,
primary key (item_id, category_id)
);
-- this is special table for dynamic columns generated
for specific
-- category so that items for this category will have
distinct
-- characteristics compared to other category
create table attributes (
id integer
primary key,
category_id integer
references categories
on delete cascade,
name varchar(100),
type varchar(20)
check (type in
('bool', 'long text', 'text', 'date', 'integer',
'float')),
);
-- this table stores value of column defined for
categories
create table values (
item_id integer
references items
on delete cascade,
attribute_id integer
references attributes
on delete cascade,
bool_value char(1)
check (bool_value in
('t', 'f')
),
long_value varchar(4000),
text_value varchar(200),
date_value datetime,
int_value integer,
float_value numeric(30, 6)
);
table values will store dynamic column's value for
particular item. the problem would be because the
table create redundancies.
i could simply change definition so that the value, no
matter of what type, will be stored in varchar(4000),
but results in problem in application.
create table values (
item_id integer
references items
on delete cascade,
attribute_id integer
references attributes
on delete cascade,
value varchar(4000)
);
the other way is to represent them in different table:
create table values_bool (
item integer
references items
on delete cascade,
attribute_id integer
references attributes
on delete cascade,
value char(1)
check (value in
('t', 'f')
)
);
which also results in problem and annoyance to
application developer.
which one is better in term of performance?
or is there any better solution?
any references or document is highly appreciated
thank you
__________________________________________________
Do You Yahoo!?
Send FREE video emails in Yahoo! Mail!
http://promo.yahoo.com/videomail/
From | Date | Subject | |
---|---|---|---|
Next Message | Daniel Andersen | 2002-01-23 04:25:18 | Re: Execute A String of Query |
Previous Message | lonh SENG | 2002-01-23 02:12:40 | Execute A String of Query |