Re: libpq sendQuery -- getResult not returning until all queries complete - Mailing list pgsql-general

From Kelly Burkhart
Subject Re: libpq sendQuery -- getResult not returning until all queries complete
Date
Msg-id AANLkTin0tLm38q42qpa1ERC8YCFTas4aGdLMD=08Zsxq@mail.gmail.com
Whole thread Raw
In response to Re: libpq sendQuery -- getResult not returning until all queries complete  (Merlin Moncure <mmoncure@gmail.com>)
Responses Re: libpq sendQuery -- getResult not returning until all queries complete  ("Daniel Verite" <daniel@manitou-mail.org>)
List pgsql-general
This should do it:

#include <stdio.h>
#include <stdlib.h>
#include <libpq-fe.h>

#define CONNINFO "your info here"
#define COMMANDS "select current_timestamp; select pg_sleep(5); select
current_timestamp"

void fatal( const char *msg ) { fprintf( stderr, "%s\n", msg ); exit(1); }

int
main()
{
    PGresult *res = 0;
    PGconn *conn = PQconnectdb( CONNINFO );
    if (!conn) fatal("PQconnectdb returned null");

    if ( PQstatus(conn) != CONNECTION_OK ) {
        PQfinish( conn );
        fatal("PQconnectdb failed");
    }

    if (!PQsendQuery(conn, COMMANDS)) {
        PQfinish( conn );
        fatal("PQsendQuery failed");
    }

    while( (res = PQgetResult( conn )) != 0 ) {
        printf("retrieved result\n");
        PQclear(res);
    }

    PQfinish( conn );
    return 0;
}



On Tue, Dec 21, 2010 at 1:26 PM, Merlin Moncure <mmoncure@gmail.com> wrote:
> On Tue, Dec 21, 2010 at 2:21 PM, Peter Geoghegan
> <peter.geoghegan86@gmail.com> wrote:
>> You can't concurrently execute queries from within a single
>> connection. Perhaps you should use multiple connections, while
>> understanding the implications of having each operate within a
>> separate snapshot.
>
> OP is not suggesting that queries run concurrently, but asking why
> result sets can't be popped off as the queries resolve.  It's a good
> question; it's probably either a bug in the database or the
> documentation (if it does not turn out to be operator error).
>
> Kelly, if you can produce small test case in C I'll double check it.
>
> merlin
>

pgsql-general by date:

Previous
From: Kelly Burkhart
Date:
Subject: Re: libpq sendQuery -- getResult not returning until all queries complete
Next
From: "Daniel Verite"
Date:
Subject: Re: libpq sendQuery -- getResult not returning until all queries complete