From: Andrew McMillan <andrew@catalyst.net.nz>
To: Philip Hallstrom <philip@adhesivemedia.com>
Cc: Chris Ryan <chris@greatbridge.com>
Cc: Jason <gee308@mediaone.net>
Cc: pgsql-php@postgresql.org
Cc: pgsql-novice@postgresql.org
Cc: pgsql-general@postgresql.org
Subject: Re: [NOVICE] Re: psql with PHP question
Date: Fri, 04 May 2001 20:07:44 +1200
Message-ID: <3AF26350.A9F7AAC0@catalyst.net.nz> (raw)
References: <Pine.BSF.4.31.0105030828560.38876-100000@oddjob.adhesivemedia.com>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-php@postgresql.org
Cc: andrew@catalyst.net.nz, philip@adhesivemedia.com, chris@greatbridge.com, gee308@mediaone.net, pgsql-novice@postgresql.org, pgsql-general@postgresql.org
Subject: Re: [NOVICE] Re: psql with PHP question
In-Reply-To: <3AF26350.A9F7AAC0@catalyst.net.nz>
References: <Pine.BSF.4.31.0105030828560.38876-100000@oddjob.adhesivemedia.com> <3AF26350.A9F7AAC0@catalyst.net.nz>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox