From c2f60711d25b256dbe2c1ddce833c5c69ca051cc Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Tue, 29 Aug 2006 22:25:08 +0000 Subject: Create a FETCH_COUNT parameter that causes psql to execute SELECT-like queries via a cursor, fetching a limited number of rows at a time and therefore not risking exhausting memory. A disadvantage of the scheme is that 'aligned' output mode will align each group of rows independently leading to odd-looking output, but all the other output formats work reasonably well. Chris Mair, with some additional hacking by moi. --- src/bin/psql/startup.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/bin/psql/startup.c') diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c index 8d3409bd194..6cbd95da9ed 100644 --- a/src/bin/psql/startup.c +++ b/src/bin/psql/startup.c @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2006, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.136 2006/08/29 15:19:51 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.137 2006/08/29 22:25:08 tgl Exp $ */ #include "postgres_fe.h" @@ -145,6 +145,8 @@ main(int argc, char *argv[]) pset.popt.topt.format = PRINT_ALIGNED; pset.popt.topt.border = 1; pset.popt.topt.pager = 1; + pset.popt.topt.start_table = true; + pset.popt.topt.stop_table = true; pset.popt.default_footer = true; pset.notty = (!isatty(fileno(stdin)) || !isatty(fileno(stdout))); @@ -798,6 +800,12 @@ singlestep_hook(const char *newval) pset.singlestep = ParseVariableBool(newval); } +static void +fetch_count_hook(const char *newval) +{ + pset.fetch_count = ParseVariableNum(newval, -1, -1, false); +} + static void echo_hook(const char *newval) { @@ -899,6 +907,7 @@ EstablishVariableSpace(void) SetVariableAssignHook(pset.vars, "QUIET", quiet_hook); SetVariableAssignHook(pset.vars, "SINGLELINE", singleline_hook); SetVariableAssignHook(pset.vars, "SINGLESTEP", singlestep_hook); + SetVariableAssignHook(pset.vars, "FETCH_COUNT", fetch_count_hook); SetVariableAssignHook(pset.vars, "ECHO", echo_hook); SetVariableAssignHook(pset.vars, "ECHO_HIDDEN", echo_hidden_hook); SetVariableAssignHook(pset.vars, "ON_ERROR_ROLLBACK", on_error_rollback_hook); -- cgit v1.2.3