Thread: pg_select Equivalent in libpq

pg_select Equivalent in libpq

From
Ecmel Ercan
Date:
Hi,

I am new to this list so if I ask a dump question please forgive me :)

I am writing a GTK+ C program using libpq.

At some point, I need to process each tuple returned by the PQexec
SELECT query as soon as it is received.  (Actually I like to insert them
in a table widget).

But when I execute PQExec, all the SELECT result is fetched first.  I
have a very big table so I need to insert each row as soon as they are
fetched from the server.

The pg_select function does this but it is in TCL library.

How can I achive the same result in libpq?

Thanks for bearing me.

Ecmel






Re: pg_select Equivalent in libpq

From
Christof Petig
Date:
Ecmel Ercan wrote:

> At some point, I need to process each tuple returned by the PQexec
> SELECT query as soon as it is received.  (Actually I like to insert them
> in a table widget).
>
> But when I execute PQExec, all the SELECT result is fetched first.  I
> have a very big table so I need to insert each row as soon as they are
> fetched from the server.
>
> The pg_select function does this but it is in TCL library.
>
> How can I achive the same result in libpq?

I would recommend a cursor. But I don't know how to do that in pq (only
with ecpg)

Christof




Re: pg_select Equivalent in libpq

From
Michael Meskes
Date:
On Tue, Sep 18, 2001 at 05:35:34PM +0200, Christof Petig wrote:
> > How can I achive the same result in libpq?
> 
> I would recommend a cursor. But I don't know how to do that in pq (only
> with ecpg)

Almost the same way, just execute a DECLARE CURSOR statement defining your
select and then issuing FETCH statements to get the data.

Michael
-- 
Michael Meskes
Michael@Fam-Meskes.De
Go SF 49ers! Go Rhein Fire!
Use Debian GNU/Linux! Use PostgreSQL!


Re: pg_select Equivalent in libpq

From
Antonio Sergio de Mello e Souza
Date:
Christof Petig wrote:

> Ecmel Ercan wrote:
>
> > At some point, I need to process each tuple returned by the PQexec
> > SELECT query as soon as it is received.  (Actually I like to insert them
> > in a table widget).
> >
> > But when I execute PQExec, all the SELECT result is fetched first.  I
> > have a very big table so I need to insert each row as soon as they are
> > fetched from the server.
> >
> > The pg_select function does this but it is in TCL library.
> >
> > How can I achive the same result in libpq?
>
> I would recommend a cursor. But I don't know how to do that in pq (only
> with ecpg)
>

See Example 1-3 in the libpq documentation:

/** testlibpq3.c Test the C version of Libpq, the Postgres frontend* library. tests the binary cursor interface**
...

Regards,

Antonio Sergio