Re: variant column type - Mailing list pgsql-general

From David Johnston
Subject Re: variant column type
Date
Msg-id 009d01cc4bbe$b59804d0$20c80e70$@yahoo.com
Whole thread Raw
In response to variant column type  (salah jubeh <s_jubeh@yahoo.com>)
Responses Re: variant column type  (Chris Travers <chris.travers@gmail.com>)
List 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.

pgsql-general by date:

Previous
From: Filippos
Date:
Subject: heavy load-high cpu itilization
Next
From: Thomas Kellerer
Date:
Subject: Re: variant column type