dbTalk Databases Forums  

Multiway associations

comp.databases.postgresql.novice comp.databases.postgresql.novice


Discuss Multiway associations in the comp.databases.postgresql.novice forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Russell Shaw
 
Posts: n/a

Default Multiway associations - 01-24-2004 , 09:46 PM






Hi,
I'm making my first database.

I have a list of parts, each of which is sold by multiple
vendors. I also have a list of vendors, each of which sell
multiple parts.

How should i arrange the tables for this that doesn't involve
having lots of empty fields "just in case" ?


---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo (AT) postgresql (DOT) org)


Reply With Quote
  #2  
Old   
Michael Glaesemann
 
Posts: n/a

Default Re: Multiway associations - 01-24-2004 , 11:05 PM






Hi Russel

On Jan 25, 2004, at 12:46 PM, Russell Shaw wrote:
Quote:
I have a list of parts, each of which is sold by multiple
vendors. I also have a list of vendors, each of which sell
multiple parts.

How should i arrange the tables for this that doesn't involve
having lots of empty fields "just in case" ?
One common way to do this is to have three tables: one suppliers, one
parts, and one suppliers-parts referencing suppliers and parts.

Does that help?

Michael Glaesemann
grzm myrealbox com


---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match



Reply With Quote
  #3  
Old   
Russell Shaw
 
Posts: n/a

Default Re: Multiway associations - 01-24-2004 , 11:23 PM



Michael Glaesemann wrote:
Quote:
Hi Russel

On Jan 25, 2004, at 12:46 PM, Russell Shaw wrote:

I have a list of parts, each of which is sold by multiple
vendors. I also have a list of vendors, each of which sell
multiple parts.

How should i arrange the tables for this that doesn't involve
having lots of empty fields "just in case" ?

One common way to do this is to have three tables: one suppliers, one
parts, and one suppliers-parts referencing suppliers and parts.
Hi,

Quote:
Does that help?
Maybe so. I thought of this and was wondering if it was the common solution.
Should it be something like:

spid supplier part
---------------------
0 sid_1 pid_1
1 sid_1 pid_2
2 sid_2 pid_2
3 sid_3 pid_3
4 sid_3 pid_1
....

Ie, the third table just stores all the combinations of parts and suppliers?


---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html



Reply With Quote
  #4  
Old   
Michael Glaesemann
 
Posts: n/a

Default Re: Multiway associations - 01-25-2004 , 12:33 AM




On Jan 25, 2004, at 2:23 PM, Russell Shaw wrote:

Quote:
Michael Glaesemann wrote:
Hi Russel
On Jan 25, 2004, at 12:46 PM, Russell Shaw wrote:
I have a list of parts, each of which is sold by multiple
vendors. I also have a list of vendors, each of which sell
multiple parts.

How should i arrange the tables for this that doesn't involve
having lots of empty fields "just in case" ?
One common way to do this is to have three tables: one suppliers, one
parts, and one suppliers-parts referencing suppliers and parts.

Hi,

Does that help?

Maybe so. I thought of this and was wondering if it was the common
solution.
Should it be something like:

spid supplier part
---------------------
0 sid_1 pid_1
1 sid_1 pid_2
2 sid_2 pid_2
3 sid_3 pid_3
4 sid_3 pid_1
...

Ie, the third table just stores all the combinations of parts and
suppliers?
Yup. The spid might be superfluous, depending on what you need your
database for. I've never needed one. You're probably only going to be
doing queries like

SELECT part FROM suppliers_parts WHERE suppplier = sid_1

or variants of these. Probably will never touch the spid column.
(Unless of course you have a particular reason for doing so

Michael Glaesemann
grzm myrealbox com


---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.