Re: Re: psql with PHP question
От | Andrew McMillan |
---|---|
Тема | Re: Re: psql with PHP question |
Дата | |
Msg-id | 3AF26350.A9F7AAC0@catalyst.net.nz обсуждение исходный текст |
Ответ на | Re: psql with PHP question (Philip Hallstrom <philip@adhesivemedia.com>) |
Список | pgsql-novice |
Philip Hallstrom wrote: > > Also... is there any reason you don't just do: > > SELECT MAX(id) FROM article > > rather than what you have below? It would get you the same thing wouldn't > it and save a query... > > On Thu, 3 May 2001, Chris Ryan wrote: > > > Jason, > > > > Look into the pg_result() function. You would use it something like > > this: > > > > $q = pg_Exec("SELECT id FROM article WHERE id=(SELECT MAX(id) FROM > > article)"); > > $maxid = pg_result($q,0,0); # pg_result($result,$row,$column_num) > > echo "The highest id is ". $maxid[0]; > > > > Hope this helps. > > > > Chris Ryan > > chris@greatbridge.com > > > > Jason wrote: > > > > > > Hi, I want to try and optimize my calls to postgreSQL from PHP. If > > > I only need one field from a select statement, what should I use? I am > > > currently using: > > > $q = pg_Exec("SELECT id FROM article WHERE id=(SELECT MAX(id) > > > FROM article)"); Or even more efficiently: SELECT id FROM article ORDER BY id DESC LIMIT 1; Since that will use an index on article.id if article is a big table, has been vacuum analyzed, and has an index available. Regards, Andrew. -- _____________________________________________________________________ Andrew McMillan, e-mail: Andrew@catalyst.net.nz Catalyst IT Ltd, PO Box 10-225, Level 22, 105 The Terrace, Wellington Me: +64(21)635-694, Fax: +64(4)499-5596, Office: +64(4)499-2267xtn709
В списке pgsql-novice по дате отправления: