pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ries van Twisk <ries@jongert.nl>
To: pgsql-sql@postgresql.org
Subject: Re: [OT] Inventory systems    (private)
Date: Tue, 3 Dec 2002 16:06:10 +0100
Message-ID: <000701c29add$841f5110$f100000a@IT001> (raw)
In-Reply-To: <200212031446.gB3Ekk6H010260@tksoft.com>

Troy, Andy,

you both are right and it was my first tought. My only concern is that would
this system be fast enough for large tables (for me large is around 250.000
unique items) and thus my attribute table would be around 2.500.000 and
5.000.000 entrys. A record for one attribute is small I think around 128
byte in size.

One thing is that every attribute must be in it's own domain. For weight for
example I have three different meanings ( 1] Pull weight 2] push weight 3]
weight of the items itself) but using the method troy suggested that would
not be a problem if I create some sort of a domain table.

Anyway so far thangs for the quick responses, I've got something to work on.

best regards,
Ries van Twisk




-----Oorspronkelijk bericht-----
Van: Troy [mailto:tjk@tksoft.com]
Verzonden: dinsdag 3 december 2002 15:47
Aan: Ries van Twisk
CC: pgsql-sql@postgresql.org
Onderwerp: Re: [SQL] [OT] Inventory systems (private)


Ries,

One solution is to create a table such as follows:

CREATE TABLE inventory (id serial, product text,
	PRIMARY KEY (id)
) ;
CREATE TABLE attributes (prodid int4, textkey text, textvalue text,
int4value int4,
	FOREIGN KEY (prodid) REFERENCES inventory (id) MATCH FULL ON DELETE CASCADE
ON UPDATE CASCADE
);

INSERT INTO inventory (id, product) VALUES (100, 'Tire');

INSERT INTO attributes (prodid, textkey, textvalue) VALUES (100, 'Type',
'matchbox tire');
INSERT INTO attributes (prodid, textkey, textvalue) VALUES (100, 'Color',
'black');
INSERT INTO attributes (prodid, textkey, int4value, textvalue) VALUES (100,
'Diameter', 12, 'mm');
INSERT INTO attributes (prodid, textkey, int4value, textvalue) VALUES (100,
'Weight', 20, 'g');
CREATE INDEX textkeys ON attributes USING btree (prodid);
CREATE INDEX textkeys2 ON attributes USING btree (prodid,textkey);

To select diameter for product id 100 (Tire):
SELECT prodid FROM attributes WHERE prodid = 100 AND textkey = 'Diameter';

To select several:
SELECT prodid,textkey,textvalue,int4value FROM attributes WHERE prodid = 100
AND textkey IN ('Diameter', 'Weight', 'Color', 'Type');


and so on.

The indexes are just a fast guess. You would need to look at the queries
you generate and decide which indexes are needed.



Cheers,


Troy

Troy Korjuslommi                Tksoft Inc.
tjk@tksoft.com




>
> Hi All,
>
> is there any whitepaper, document or website that can point me to how to
> setup a inventory system?
> I'm particulary interested how other people solve the problem of a unknown
> number of attributes to a inventory item.
>
> example:
> BAL                <-- Inventory Item
> 	- Color      <- Attribute
> 	- Diameter   <- Attribute
> 	- Weight     <- Attribute
>
> Car                <-- Inventory Item
> 	- Speed      <- Attribute
> 	- Size       <- Attribute
> 	- Weight     <- Attribute
> 	- Color      <- Attribute
>
> Computer                <-- Inventory Item
> 	- Brand           <- Attribute
> 	- Weight          <- Attribute
> 	- Windows/Linux   <- Attribute
>
>
> I can ofcource add any number of columns to a table but for a lot of items
> there will be a lot of NULL values and currently I don't know how many
> attrubutes one item can have (possible between 10 and 20). This can even
> change in feature opon request.
>
> Ries
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>




view thread (6+ messages)  latest in thread

Message-ID: <000701c29add$841f5110$f100000a@IT001>
Permalink:  ../000701c29add$841f5110$f100000a@IT001/
Also on:    postgresql.org/message-id/000701c29add$841f5110$f100000a@IT001

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: ries@jongert.nl
  Subject: Re: [OT] Inventory systems    (private)
  In-Reply-To: <000701c29add$841f5110$f100000a@IT001>

* 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