Need sql to pull data from terribly architected table - Mailing list pgsql-general

From Gauthier, Dave
Subject Need sql to pull data from terribly architected table
Date
Msg-id 0AD01C53605506449BA127FB8B99E5E13E0F8E70@FMSMSX105.amr.corp.intel.com
Whole thread Raw
Responses Re: Need sql to pull data from terribly architected table  (Chris Curvey <chris@chriscurvey.com>)
Re: Need sql to pull data from terribly architected table  ("David Johnston" <polobo@yahoo.com>)
Re: Need sql to pull data from terribly architected table  (Steve Litt <slitt@troubleshooters.com>)
List pgsql-general

Here's the deal...

 

Instead of architecting and loading a table like...  

create teble foo (col1 text, col2 text, col3 text, col4 text, col5 text);  

insert into foo (col1,col2,col3,col4,col5) values ('c1',null,'c3','c4',null);

 

They did this instead...

 

create table foo (property text, value text);

insert into foo (property, value) values ('col1','c1'), ('col3','c3'), ('col4','c4');

 

Notice how "col2" and "col5" were simply left out of the table in the 2nd model to indicate null.

 

The question is how to do this model 1 query for model 2...

 

select col1,col2 from foo where col4='c4' and col5 <> 'xxx';

 

I know I have to use outer joins to deal with the potential of nulls.  But I don't know how to construct this.  I won't list my failed attempts (so as not to embarass myself :-))

 

Thanks in Advance !

 

 

pgsql-general by date:

Previous
From: Scott Marlowe
Date:
Subject: Re: 9.1 to 9.2 requires a dump/reload?
Next
From: Chris Curvey
Date:
Subject: Re: Need sql to pull data from terribly architected table