pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Mohd Toha Taifor <mtzza@yahoo.com>
To: pgsql-admin@postgresql.org
Subject: Dynamic columns
Date: Tue, 22 Jan 2002 19:53:37 -0800 (PST)
Message-ID: <20020123035337.66997.qmail@web13807.mail.yahoo.com> (raw)

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/



Message-ID: <20020123035337.66997.qmail@web13807.mail.yahoo.com>
Permalink:  ../20020123035337.66997.qmail@web13807.mail.yahoo.com/
Also on:    postgresql.org/message-id/20020123035337.66997.qmail@web13807.mail.yahoo.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: mtzza@yahoo.com
  Subject: Re: Dynamic columns
  In-Reply-To: <20020123035337.66997.qmail@web13807.mail.yahoo.com>
  References: <20020123035337.66997.qmail@web13807.mail.yahoo.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox