[SQL] How to FindNearest
How to implement the functionality similar to the BDE/Paradox TTable.FindNearest? Suppose we have huge table. On the screen we need to show contents of that table in the Grid and under that Grid user can input in TextBox some letters. OnChange of this TextBox we need to make current row selection in the Grid on the row with value of some column nearest to the user input in the TextBox. How this can be implemented in PostgreSQL? At my first sight: I found there is CURSOR functionality which can move that cursor through the ResultSet. But we can move it just relatively phisical row number. Is there any chance to make cursor move to the row by some rule based on the row values? All possible approaches and ideas highly appreciated. There is just one requirement - the performance, it should work as fast as possible. Regards, Alexander Ilyin ---(end of broadcast)--- TIP 3: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faq
Re: [SQL] tree-structured query
On fös, 2006-09-29 at 15:00 -0700, chester c young wrote: > in a simple tree structured table > > table t( > id primary key, > pnt_id references t( id ), > name > ); > > does anyone know an easy howbeit sneaky way of determining ancestory > and decendency without recursive functions, how about CREATE TABLE ancestry ( ans_id int, desc_id int ) for each record of t , for each ancestor of id, insert a record (ans_id,id) into anscestry this can be maintained by application, or by triggers. to get all ancestors of a particular id X: SELECT name from t JOIN ancestry ON (id=ans_id) WHERE desc_id=X; to get descendents: SELECT name from t JOIN ancestry ON (id=desc_id) WHERE ans_id=X; indexes on ancestry(ans_id) and ancestry(desc_id) might be called for. hope this helps gnari ---(end of broadcast)--- TIP 4: Have you searched our list archives? http://archives.postgresql.org
