Re: selecting a random record

From: "Arun Malhotra - Roll No(dot)99007" <arun(at)gdit(dot)iiit(dot)net>
To: Culley Harrelson <culleyharrelson(at)yahoo(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: selecting a random record
Date: 2001-02-11 09:21:53
Message-ID: Pine.LNX.4.21.0102111429160.12835-100000@gdit.iiit.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi
I dont know exactly why u need this but this can be done in MySQL/PERL

create a file called random.pl
i select a random reecord from Temp table with PK temp_id

#! /usr/bin/perl -w

use Mysql;
$i = (10*rand())%10;

$dbh = Mysql->Connect('localhost','DBNAME','root');

$sth = $dbh->Query("Select * from Temp");
$no = $dbh->Query("Select COUNT(temp_id) from Temp");
@nr = $sth->FetchRow;

for($n=0; $n<@nr[0]; $n++)
{
@row = $sth->FetchRow;
if($n == $i)
{
print @row;
}
}

On Tue, 6 Feb 2001, Culley Harrelson wrote:

> Any suggestions on how to select a random record from
> any given table?
>
> Culley
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Auctions - Buy the things you want at great prices.
> http://auctions.yahoo.com/
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jarungwit J. 2001-02-12 05:56:04 Re: startup Postgres on NT
Previous Message Alex Pilosov 2001-02-11 08:27:33 Re: what's wrong with this query