Re: [SQL] Self-referencing table question

2005-03-24 Thread Sean Davis
On Mar 24, 2005, at 2:37 PM, Edmund Bacon wrote: Sean Davis wrote: Nice. Thanks for doing my work for me! Yeah, well put it down to a certain amount of curiosity and a slack period at work ... I guess I will have to think about it more seriously. It could be a slight bit complicated because my c

Re: [SQL] Self-referencing table question

2005-03-24 Thread Edmund Bacon
Sean Davis wrote: Nice. Thanks for doing my work for me! Yeah, well put it down to a certain amount of curiosity and a slack period at work ... I guess I will have to think about it more seriously. It could be a slight bit complicated because my code is running under mod_perl, so connections ar

Re: [SQL] Self-referencing table question

2005-03-24 Thread Sean Davis
On Mar 24, 2005, at 1:11 PM, Edmund Bacon wrote: Sean Davis wrote: Thanks. I thought about that a bit and it seems like it is highly likely to be expensive for a single query (though I should probably try it at some point). If I do find myself reformatting results after response to user input

Re: [SQL] Self-referencing table question

2005-03-24 Thread Edmund Bacon
Sean Davis wrote: Thanks. I thought about that a bit and it seems like it is highly likely to be expensive for a single query (though I should probably try it at some point). If I do find myself reformatting results after response to user input (i.e., reusing the query), though, then your sol

Re: [SQL] Self-referencing table question

2005-03-24 Thread Sean Davis
Thanks. I thought about that a bit and it seems like it is highly likely to be expensive for a single query (though I should probably try it at some point). If I do find myself reformatting results after response to user input (i.e., reusing the query), though, then your solution is likely to

Re: [SQL] Self-referencing table question

2005-03-24 Thread Edmund Bacon
Sometimes using a temp table is a better idea: e.g. -- start by creating a temp table 'tids' that hold the to_ids that -- we are interested in. SELECT to_id INTO TEMP TABLE tids FROM correlation WHERE from_id = 1234 ORDER BY val DESC limit 100; -- The following temp table makes use of t

Re: [SQL] Self-referencing table question

2005-03-23 Thread Sean Davis
On Mar 22, 2005, at 7:07 PM, Sean Davis wrote: - Original Message - From: "Richard Huxton" To: "Sean Davis" <[EMAIL PROTECTED]> Cc: "PostgreSQL SQL" Sent: Tuesday, March 22, 2005 3:59 PM Subject: Re: [SQL] Self-referencing table question Sean Davis

Re: [SQL] Self-referencing table question

2005-03-22 Thread Sean Davis
- Original Message - From: "Richard Huxton" To: "Sean Davis" <[EMAIL PROTECTED]> Cc: "PostgreSQL SQL" Sent: Tuesday, March 22, 2005 3:59 PM Subject: Re: [SQL] Self-referencing table question Sean Davis wrote: I answer my own question, if only for m

Re: [SQL] Self-referencing table question

2005-03-22 Thread Richard Huxton
Sean Davis wrote: I answer my own question, if only for my own records. The following query is about 5-6 times faster than the original. Of course, if anyone else has other ideas, I'd be happy to hear them. Sean explain analyze select from_id,to_id,val from exprsdb.correlation where from_i

Re: [SQL] Self-referencing table question

2005-03-22 Thread Sean Davis
I answer my own question, if only for my own records. The following query is about 5-6 times faster than the original. Of course, if anyone else has other ideas, I'd be happy to hear them. Sean explain analyze select from_id,to_id,val from exprsdb.correlation where from_id in (select to_id

[SQL] Self-referencing table question

2005-03-22 Thread Sean Davis
I have a table that looks like: Column | Type | Modifiers | Description -+--+---+- from_id | integer | not null | to_id | integer | not null | val | numeric(4,3) | | Indexes: "correlation_pkey" PRIMARY KEY, btree (

Re: [SQL] Self-Referencing

2001-03-29 Thread Cedar Cox
On Wed, 28 Mar 2001, David Olbersen wrote: > Hello, > > I have a feeling this isn't going to make much sense, but I'm gonig to try > anyway. > > What I'd like to do is be able to refer to an outer-SELECT from an > inner-SELECT. I hope this makes sense. > > I need to be able to refer

Re: [SQL] Self-Referencing

2001-03-29 Thread Christof Glaser
On Thursday, 29. March 2001 01:38, David Olbersen wrote: [snip] > SELECT > building_id, > num_buildings, > ( > SELECT count( building_id ) > FROM building_portals > WHERE building_id = THIS.building_id > ) > FROM buildings; Try this query (untested), using

[SQL] Self-Referencing

2001-03-28 Thread David Olbersen
Hello, I have a feeling this isn't going to make much sense, but I'm gonig to try anyway. What I'd like to do is be able to refer to an outer-SELECT from an inner-SELECT. I hope this makes sense. I need to be able to refer to the row that's being processed in a SELECT. I'm going to