Re: libpq: How are result sets fetched behind the scene?

From: Christian Barthel <bch(at)online(dot)de>
To: Sebastien FLAESCH <sf(at)4js(dot)com>
Cc: pgsql-sql(at)lists(dot)postgresql(dot)org
Subject: Re: libpq: How are result sets fetched behind the scene?
Date: 2019-09-07 12:43:58
Message-ID: 87zhjg8eep.fsf@x230.onfire.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Sebastien FLAESCH <sf(at)4js(dot)com> writes:

> Is the whole result set fetched to the client app, not matter what row
> number is provided to the first PQgetvalue() call (or similar API call
> on result set data or meta-data)?

I have tested this as well and came to the same result as you.
The entire result set seems to be fetched at once.
Attached is a test program: I have loaded 30MB of random strings
and did a simple SELECT on the random data. I stopped the output
with getchar() and looked at the network traffic and the memory
usage with top(1). Everything gets allocated and fetched at once
as far as I can see.

However, I would not build an application that "depends" on this
behavior. I think that it is better to use a declared cursor and
use FETCH.
--
Christian Barthel <bch(at)online(dot)de>

Attachment Content-Type Size
pg-fetchtest.c text/x-csrc 2.1 KB

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Rob Sargent 2019-09-07 14:07:49 Re: How do I enabled Windows 10 to be able to run PSQL etc
Previous Message Karen Goh 2019-09-07 12:26:13 How do I enabled Windows 10 to be able to run PSQL etc