Re: variant column type

From: "David Johnston" <polobo(at)yahoo(dot)com>
To: "'salah jubeh'" <s_jubeh(at)yahoo(dot)com>, "'pgsql'" <pgsql-general(at)postgresql(dot)org>
Subject: Re: variant column type
Date: 2011-07-26 18:06:14
Message-ID: 009d01cc4bbe$b59804d0$20c80e70$@yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

the car speed is 240

the car has an airbag

Here the first value is integer and the second value is boolean. Consider
that I have this table structure

feature (feature id feature name)

car (car id, .... )

car_feature (car id, feature id, value). the value attribute might have
different domains. How can I model this using postgres and using ANSI
compliant design ?

Regards

Given "feature" and "car-feature" tables the presence of absence of an entry
in "car-feature" will accomplish your desire for true/false - i.e., "the car
has an airbag". By abstracting just a little every "feature" can be boiled
down to a label/ID and then the added to "feature" and associated via
"car-feature".

In your example you could create a feature called "Top Speed - 240kph"

If every car is going to have a particular "feature" and only the "value"
matters you could considering adding a "car-properties" table:

car_property (car id, top_speed, etc.) and populate the top_speed column
with whatever value is applicable or leave it NULL if unknown or N/A. The
relationship between "car" and "car_property" would be one-to-one (1-to-1)

Dave J.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Thomas Kellerer 2011-07-26 18:12:15 Re: variant column type
Previous Message Filippos 2011-07-26 17:47:19 heavy load-high cpu itilization