dbTalk Databases Forums  

Exact or less specific match ?

comp.databases.postgresql.general comp.databases.postgresql.general


Discuss Exact or less specific match ? in the comp.databases.postgresql.general forum.



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

Default Exact or less specific match ? - 10-27-2004 , 10:33 AM






Hi.

i have table like this:

create table my_data (
cond_1 int8,cond_2 varchar(),cond_3 .... cond_n whatrver ,data text)

This table represents a simple tree structure with known max level (n) .
This table is filled with data, but branches have not a same depth.

Now I need to select from table

select data from my_data where cond_1=x AND cond_2='blah' And cond_3= .....
AND cond_n=whatewer

But, this tree have not a same depth in all his branches. So I need to
select Exact match, and, if the exact match is not possible (ie if there is
not line that fit WHERE condition ),

to select with WHERE cond_1=x AND cond_2='blah' And cond_3= ..... AND
cond_(n-1)=whatewer and so on until the 'data' is not empty or top of the
tree reached (ie if not match, find data from upper node of the tree).

I know, that similar effects can be reached with COALESCE,


select coalesce ((select data from my_data where cond_1=x AND cond_2='blah'
And cond_3= ..... AND cond_n=whatewer),(select data from my_data where
cond_1=x AND cond_2='blah' And cond_3= ..... AND cond_(n-1)=whatewer)
,...........,(select data from my_data where cond_1=x ))


but i think it is not ideal, because it needs to perform a N subselects,
what can eat a lot of machine time...



is there some other way to do exact or less specific match ?


Thank you. please execuse my bad english


---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend


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.