I just played with this for the first time after seeing a question here:
https://www.postgresql.org/message-id/flat/VI1PR0701MB271869EC2BEDD69E1D0CEC86AE6D0%40VI1PR0701MB2718.eurprd07.prod.outlook.com

This is kind of neat, and allows returning arbitrarily large result sets to the
client library in constant RAM.

However I think it's only useful for iteration, and so it's inconsistent with
our use of sequence protocol :(

res = pgdb.query('SELECT generate_series(1,999999)')
res[999] # it would have no way to get that without reading the result from
# scratch, possibly after re-executing the query, which is a non-starter...

Attached is another munged copy of t.c I used while checking its behavior
(which isn't particularly clear from the docs).

Justin
// make CFLAGS='-std=gnu99 -Wall -Wextra -O3 -g -I /usr/include/postgresql' LDLIBS=-lpq t
// PGDATABASE=postgres ./t

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

void f(char **argv)
{
	PGconn *conn = PQconnectdb("");
	if (PQstatus(conn)!=CONNECTION_OK ||
		!PQsendQuery(conn, "SELECT generate_series(1,99999)") ||
		!PQsetSingleRowMode(conn)) {
		printf ("%s", PQerrorMessage(conn));
		exit(1);
	}

	PGresult *res;
	while ((res = PQgetResult(conn))) {
		// if (PQresultStatus(res)!=PGRES_COMMAND_OK && PQresultStatus(res)!=PGRES_TUPLES_OK) {
		if (PQresultStatus(res)!=PGRES_SINGLE_TUPLE) {
			printf ("%s", PQresultErrorMessage(res));
			exit(1);
		}

		printf("%s\n", PQgetvalue(res, 0, 0));
		PQclear(res);
	}
}

int main(int argc, char **argv)
{
	f(argv);
	return 0;
}
_______________________________________________
PyGreSQL mailing list
PyGreSQL@Vex.Net
https://mail.vex.net/mailman/listinfo/pygresql

Reply via email to