Re: [GENERAL] select single entry and its neighbours using direct-acess to index?

2004-12-06 Thread Greg Stark
Pierre-Frédéric Caillaud <[EMAIL PROTECTED]> writes: > One could always use ARRAY[name,name2] > ARRAY['b','a'] > But it is NOT index-friendly... It won't use an existing two-column index but you can create an expression index on array[name,name2] and this expression will use it. It w

Re: [GENERAL] select single entry and its neighbours using direct-acess to index?

2004-12-06 Thread Pierre-Frédéric Caillaud
I thought the planner had an automatic rewriter for these situations. No. There was a prior discussion of this, saying that we really ought to support the SQL-spec row comparison syntax: What I meant was that I thought the planner could rewrite : (A and C) or (A AND B) as A and (B or

Re: [GENERAL] select single entry and its neighbours using direct-acess to index?

2004-12-06 Thread Tom Lane
=?iso-8859-15?Q?Pierre-Fr=E9d=E9ric_Caillaud?= <[EMAIL PROTECTED]> writes: > SELECT * FROM test WHERE (name='b' and name2>'a') OR (name>'b') ORDER BY > name,name2 ASC LIMIT 1; >> Write that WHERE clause instead as: >> WHERE name>='b' AND (name>'b' OR (name='b' AND name2>'a')) >> This is logically e

Re: [GENERAL] select single entry and its neighbours using direct-acess to index?

2004-12-06 Thread Pierre-Frédéric Caillaud
SELECT * FROM test WHERE (name='b' and name2>'a') OR (name>'b') ORDER BY name,name2 ASC LIMIT 1; Write that WHERE clause instead as: WHERE name>='b' AND (name>'b' OR (name='b' AND name2>'a')) This is logically equivalent, but it gives the planner a better handle on how to use an index scan to sat

Re: [GENERAL] select single entry and its neighbours using direct-acess to index?

2004-12-06 Thread Andrew - Supernews
On 2004-12-06, Pierre-Frédéric Caillaud <[EMAIL PROTECTED]> wrote: > SELECT * FROM test WHERE (name='b' and name2>'a') OR (name>'b') ORDER BY > name,name2 ASC LIMIT 1; Write that WHERE clause instead as: WHERE name>='b' AND (name>'b' OR (name='b' AND name2>'a')) This is logically equivalent,

Re: [GENERAL] select single entry and its neighbours using direct-acess to index?

2004-12-06 Thread Pierre-Frédéric Caillaud
sorry for being unclear. but you guessed right. ID is UNIQUE and and I want to select a row by its ID and also get the previous and next ones in the name, name2-order. For the selected row I need all datafields and for the next and previous I need only the ID (to have it referenced on the dat

Re: [GENERAL] select single entry and its neighbours using direct-acess

2004-12-06 Thread peter pilsl
Pierre-Frédéric Caillaud wrote: select id from mytable where id=45 order by name,name2; Why do you want to select id if you already know it ? Do you not want to specify a starting value for name and name2 ? I'll presume you want to select a row by its 'id' and then get the previous

Re: [GENERAL] select single entry and its neighbours using direct-acess to index?

2004-12-06 Thread Pierre-Frédéric Caillaud
select id from mytable where id=45 order by name,name2; Why do you want to select id if you already know it ? Do you not want to specify a starting value for name and name2 ? I'll presume you want to select a row by its 'id' and then get the previous and next ones in the name, name2

[GENERAL] select single entry and its neighbours using direct-acess to index?

2004-12-06 Thread peter pilsl
Is there an easy solution for this? I'd like to select a single entry from a table and the entries that would be previous and next given to a certain order. like select id from mytable where id=45 order by name,name2; and then I'd like to select the two entries that would come before and after a