Hey all,
this is my first post on this forum...
What I am going to describe is properly a 'classic' problem and will have a clasic solution,
I am just not sure about this so I would like to have your opinion on this:
We have a database with part_numbers, product groups, product sub-groups, vehicles names, vehicle model, division name country, year etc.. etc..
That means for each country we can lookup what vehicle in what country we have and what parts are availabe in a specific year,
I think you get the idea for such a warehouse database..
in a sense they can be ordered like this:
world -> market -> country -> year -> division -> vehicle -> vehicle model -> product -> sub-product -> part_number
Here are some examples:
world -> europe -> Germany -> 2006 -> Saab -> 9-3 -> 9-3 Saloon -> interior -> electronics -> 12345678
world -> europe -> Germany -> 2006 -> Saab -> 9-3 -> 9-3 TurboX -> exterior -> wheels -> 3424455
world -> America -> USA -> 2007 -> Saab -> 9-3 -> 9-3 TurboX -> exterior -> wheels -> 4234563
Some properties of the data:
- We do have proper primary keys for each 'object'
- Each copy/description/image can be created in different languages
- Each vehicle can appear in different years, but they are the same vehicle (same primary key)
- Each vehicle can appear in different countries, but they are the same...
- Each part can be applied to one or more vehicles under it's own product/sun product group,
however this can differ per vehicle.. so some part might not always fall under interior/electronics but might be under
exterior/electronics for an other vehicle
- I call each node type 'meta data', that is additional data that belongs to a node. This contains additional data that os specific for each node type
This is what I had in mind for it's design, it's based on Celko nested set, however I am not 100% sure if this is the correct appraoch.
My nested set would look more or less like this:
CREATE TABLE product_portfolio
(
item_id character varying(36) NOT NULL, -- UUID that identifies this node
lgt integer NOT NULL,
rgt integer NOT NULL,
level integer NOT NULL, -- Indicates what sort of object it is (division, vehicle, part number vehicle_model etc....)
ref_id character varying(36) NOT NULL, -- UUID that references a other meta data object 1-1 relation
)
One of my meta data tables could look like this
CREATE TABLE vehicles
(
item_id character varying(36) NOT NULL, -- UUID that identifies this vehicle
vehicle_name text,
vehicle_attribute text,
vehicle_weight text,
vehicle_image text
)
CREATE TABLE part_numbers
(
item_id character varying(36) NOT NULL, -- UUID that identifies this vehicle
part_description text,
part_price number,
part_image text
)
The idea is to let ref_id in the product_portfolio reference my meta data rows in other tables and that the level number tells
me what meta data type it is.
By doing this I can use the switch command in SQL to call the correct name and thus build a tree..
Something like this:
SELECT amtc.*,
CASE
WHEN level=4 THEN
(SELECT vehicle_name FROM vehicles a WHERE a.item_id = pp.item_id)
WHEN level=5 THEN
(SELECT division_name FROM divisions a WHERE a.item_id = pp.item_id)
WHEN level=6 THEN
(SELECT product_group_na,e FROM product_groups a WHERE a.item_id = pp.item_id)
WHEN level=xxx THEN
......
ELSE
'
TBD'
END AS translation
FROM product_portfolio pp;
That means for each node type, I need to have a seperate table to specify the meta data for the node.
What's your thought on this, and would it be the right approach for this problem?
If you have any pointers to pages that explains this problem (with solution??) then that would be great,
since I don't think this is a unique problem...
I did read about Graphs in SQL (is this a graph?) But currently don't full understand how that would work..
thanks,
Ries