From: Justin Long <justinlong@strategicnetwork.org>
To: 'pgsql-sql@postgreSQL.org' <pgsql-sql@postgreSQL.org>
Subject: Selecting random element?
Date: Mon, 6 Mar 2000 10:31:39 -0500
Message-ID: <01BF8757.2898CBB0.justinlong@strategicnetwork.org> (raw)
Does anyone have a way to select a random element without doing a complete select on the database first?
For example, right now I would have to (under PHP3):
$rs = pg_exec($db,"SELECT * FROM database");
$rec = pg_fetch_object($rs,rand(1,pg_numrows($rs)));
It would be a lot easier to just do a
$rs = pg_exec($db,"SELECT * from database RANDOM")
or some such where it would select a random row.
_____
Justin Long
Network for Strategic Missions
1732 South Park Court, Chesapeake, VA 23320
Ofc 757-420-4500, Fax 757-226-5006, Email justinlong@strategicnetwork.org
Never retreat. Never surrender. Never cut a deal with a dragon.
http://www.strategicnetwork.org
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-sql@postgresql.org
Cc: justinlong@strategicnetwork.org
Subject: Re: Selecting random element?
In-Reply-To: <01BF8757.2898CBB0.justinlong@strategicnetwork.org>
References: <01BF8757.2898CBB0.justinlong@strategicnetwork.org>
* 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