On Mon, October 23, 2006 8:58 pm, Chris wrote: > Richard Lynch wrote: >> On Fri, October 20, 2006 10:04 am, Fourat Zouari wrote: >>> I have PHP/PostgreSQL application were i got a search page with >>> some >>> items >>> to search, am building the search query on server side. >>> >>> I need to display a paginated search and for this i need to get the >>> total >>> count of lines matching the search before OFFSET/LIMITing my page, >>> am >>> i >>> obliged to repeat the query twice ??? first to get the total count, >>> second >>> to get my page. >>> >>> it's very heavy >>> >>> Any one's suggesting better doing ? >> >> Use a cursor. > > Cursors won't help - they don't store the info about how many results > the query would fetch (I asked this question a few months ago on one > of > the postgres lists). The Original Post made it sound like getting the total count was a means, not an end... :-) I believe the following is true: A PostgreSQL cursor doesn't store how many results it would fetch because it may not always even KNOW how many results it would fetch, because it may be able to avoid actually doing all the work to compute all the rows if it can prove that it has the correct first N rows to return when all you asked for was N so far. I won't swear to that in court, mind you, but I think they've got some optimizations that work that way... -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some starving artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php