Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql Novice > Check existence...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 2 Topic 3023 of 3175
Post > Topic >>

Check existence of combination in an M.N relation

by erik@[EMAIL PROTECTED] (Erik Cederstrand) Feb 29, 2008 at 04:25 PM

Hi list

I want to store sets of configuration options in an m:n table. Each 
option is defined by a parameter/value pair, and each set of options has 
a unique ID (the data describes non-default hardware configuration of a 
group of computers).

Now, given an arbitrary set of options, how do I check if that exact 
combination already exists, and either return the ID if it exists, or 
insert the set and return the new ID?

The relation is defined as:

CREATE TABLE mach_conf (
   id int4 NOT NULL,
   param varchar(64) NOT NULL,
   value varchar(256) NOT NULL,
   CONSTRAINT mach_conf_id PRIMARY KEY (id, param, value)
)

Example table:

id   param   value
---------------------
1    hz      2.6G
1    ncpu    8
1    ram     4G
2    hz      2.6G
3    ncpu    4
3    arch    i386

If I have the set [ncpu=4, arch=i386] I want to have id=3 returned. If I 
have the set [ncpu=4] I want id=4 returned.

How would I go about this? I'm on PostgreSQL8.2.

Thanks,
Erik

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

               http://archives.postgresql.org
 




 2 Posts in Topic:
Check existence of combination in an M.N relation
erik@[EMAIL PROTECTED] (  2008-02-29 16:25:42 
Re: Check existence of combination in an M.N relation
rdeleonp@[EMAIL PROTECTED  2008-02-29 14:57:44 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan13V112 Sun Jul 20 4:25:24 CDT 2008.