Thread: Rows in tables...

Rows in tables...

From
Herb Pabst
Date:
What is the easiest way to get the total number of
rows in a table? I want to do a random pick from a
table and need to know how many rows are in the
table.

Do I do a "SELECT * FROM table" and use the info
from this, or will a select return all the data?
This is where I'm hazy. Or does fetch_row actually
return the data?

Any help is appreciated,
Herbie Pabst


Re: Rows in tables...

From
Dorin Grunberg
Date:
Use: pg_NumRows($result)

and

$result = pg_Exec ($conn, $sql);

All the best,
Dorin Grunberg

At 04:40 PM 2/19/2001 -0500, Herb Pabst wrote:
>What is the easiest way to get the total number of
>rows in a table? I want to do a random pick from a
>table and need to know how many rows are in the
>table.
>
>Do I do a "SELECT * FROM table" and use the info
>from this, or will a select return all the data?
>This is where I'm hazy. Or does fetch_row actually
>return the data?
>
>Any help is appreciated,
>Herbie Pabst


Re: Rows in tables...

From
"Mitch Vincent"
Date:
SELECT count(*) FROM <tablename>

Then get the count result. You can count a single value in the table if you
want to also..

-Mitch

----- Original Message -----
From: "Herb Pabst" <herbie@nextearth.com>
To: "pgsql-php" <pgsql-php@postgresql.org>
Sent: Monday, February 19, 2001 4:40 PM
Subject: [PHP] Rows in tables...


> What is the easiest way to get the total number of
> rows in a table? I want to do a random pick from a
> table and need to know how many rows are in the
> table.
>
> Do I do a "SELECT * FROM table" and use the info
> from this, or will a select return all the data?
> This is where I'm hazy. Or does fetch_row actually
> return the data?
>
> Any help is appreciated,
> Herbie Pabst
>
>


Re: Rows in tables...

From
"Dan Wilson"
Date:
You may be looking for a query like this:

SELECT * FROM [table] ORDER BY random() LIMIT 1

This will automtically select a random row and only return 1 tuple.  This
will cut down on your query time and the memory usage.

I don't know if that was what you are trying to do.

-Dan


> What is the easiest way to get the total number of
> rows in a table? I want to do a random pick from a
> table and need to know how many rows are in the
> table.
>
> Do I do a "SELECT * FROM table" and use the info
> from this, or will a select return all the data?
> This is where I'm hazy. Or does fetch_row actually
> return the data?
>
> Any help is appreciated,
> Herbie Pabst
>