Re: How to get many data at once?

From: Bill Moran <wmoran(at)collaborativefusion(dot)com>
To: "窦德厚(ddh)" <doudehou(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: How to get many data at once?
Date: 2008-08-08 14:35:33
Message-ID: 20080808103533.93b2d5dc.wmoran@collaborativefusion.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

In response to "窦德厚(ddh)" <doudehou(at)gmail(dot)com>:

> Hi, if I have such a table:
>
> t_ref_id t_data
> --------------------
> 1 'abc'
> 2 '321'
> 1 'ddd'
> 2 'xyz'
> 9 '777'
> ...
>
>
> I want to get data with a special t_ref_id:
>
> SELECT t_data FROM THETABLE WHERE t_ref_id = '1';
>
> I must use a while loop to extract the data (I'm using PHP):
>
> $rows = array();
> while (($row = pgsql_fetch_assoc($result) !== false) {
> $rows[] = $row;
> }
>
> And if there are many matched rows, such as many hundreds or thousands of
> rows, I think such a loop maybe inefficient.

You're wrong. It's pretty much the only way.

The only way you can improve on that is to process that row immediately
instead of copying it from $row to $rows[].

> How to do this in a more efficient way?

Use a more efficient language, such as C, instead of PHP.

--
Bill Moran
Collaborative Fusion Inc.
http://people.collaborativefusion.com/~wmoran/

wmoran(at)collaborativefusion(dot)com
Phone: 412-422-3463x4023

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Lucas Felix 2008-08-08 15:00:20 psqlodbc on Vista Ultimate 64
Previous Message Magnus Hagander 2008-08-08 14:31:02 Re: Need info on installer