Skip to content

Commit 0778116

Browse files
author
Neil Conway
committed
Per discussion on -hackers, this patch changes psql's "expanded" output
mode to only affect the presentation of normal query results, not the output of psql slash commands. Documentation updated. I also made some unrelated minor psql cleanup. Per suggestion from Stuart Cooper.
1 parent 8c05ca7 commit 0778116

File tree

7 files changed

+77
-44
lines changed

7 files changed

+77
-44
lines changed

doc/src/sgml/ref/psql-ref.sgml

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.143 2005/06/13 02:40:08 neilc Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.144 2005/06/13 06:36:22 neilc Exp $
33
PostgreSQL documentation
44
-->
55

@@ -433,8 +433,8 @@ PostgreSQL documentation
433433
<term><option>--expanded</></term>
434434
<listitem>
435435
<para>
436-
Turn on the extended table formatting mode. This is equivalent to the
437-
command <command>\x</command>.
436+
Turn on the expanded table formatting mode. This is equivalent to the
437+
<command>\x</command> command.
438438
</para>
439439
</listitem>
440440
</varlistentry>
@@ -1389,7 +1389,7 @@ lo_import 152801
13891389
<literal>aligned</literal>, <literal>html</literal>,
13901390
<literal>latex</literal>, or <literal>troff-ms</literal>.
13911391
Unique abbreviations are allowed. (That would mean one letter
1392-
is enough.)
1392+
is enough.)
13931393
</para>
13941394

13951395
<para>
@@ -1429,10 +1429,13 @@ lo_import 152801
14291429
<listitem>
14301430
<para>
14311431
Toggles between regular and expanded format. When expanded
1432-
format is enabled, all output has two columns with the column
1433-
name on the left and the data on the right. This mode is
1434-
useful if the data wouldn't fit on the screen in the normal
1435-
<quote>horizontal</quote> mode.
1432+
format is enabled, query results are displayed in two
1433+
columns, with the column name on the left and the data on
1434+
the right. This option only affects how normal query results
1435+
are displayed; the output of <application>psql</application>
1436+
meta-commands is always presented using the regular
1437+
format. This mode is useful if the data wouldn't fit on the
1438+
screen in the normal <quote>horizontal</quote> mode.
14361439
</para>
14371440

14381441
<para>
@@ -1722,7 +1725,7 @@ lo_import 152801
17221725
<term><literal>\x</literal></term>
17231726
<listitem>
17241727
<para>
1725-
Toggles extended table formatting mode. As such it is equivalent to
1728+
Toggles expanded table formatting mode. As such it is equivalent to
17261729
<literal>\pset expanded</literal>.
17271730
</para>
17281731
</listitem>

src/bin/psql/command.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.145 2005/06/09 23:28:09 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.146 2005/06/13 06:36:22 neilc Exp $
77
*/
88
#include "postgres_fe.h"
99
#include "command.h"
@@ -114,11 +114,6 @@ HandleSlashCmds(PsqlScanState scan_state,
114114
{
115115
/* adjust cmd for possible messages below */
116116
cmd[1] = '\0';
117-
118-
#if 0 /* turned out to be too annoying */
119-
if (isalpha((unsigned char) cmd[0]))
120-
psql_error("Warning: This syntax is deprecated.\n");
121-
#endif
122117
}
123118
}
124119

src/bin/psql/common.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.100 2005/06/10 14:49:31 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.101 2005/06/13 06:36:22 neilc Exp $
77
*/
88
#include "postgres_fe.h"
99
#include "common.h"
@@ -64,7 +64,6 @@ extern bool prompt_state;
6464

6565
static bool command_no_begin(const char *query);
6666

67-
6867
/*
6968
* "Safe" wrapper around strdup()
7069
*/
@@ -189,7 +188,7 @@ setQFout(const char *fname)
189188
*
190189
*/
191190
void
192-
psql_error(const char *fmt,...)
191+
psql_error(const char *fmt, ...)
193192
{
194193
va_list ap;
195194

@@ -784,6 +783,10 @@ PrintNotifications(void)
784783
static bool
785784
PrintQueryTuples(const PGresult *results)
786785
{
786+
printQueryOpt my_popt = pset.popt;
787+
788+
my_popt.topt.normal_query = true;
789+
787790
/* write output to \g argument, if any */
788791
if (pset.gfname)
789792
{
@@ -800,7 +803,7 @@ PrintQueryTuples(const PGresult *results)
800803
return false;
801804
}
802805

803-
printQuery(results, &pset.popt, pset.queryFout);
806+
printQuery(results, &my_popt, pset.queryFout);
804807

805808
/* close file/pipe, restore old setting */
806809
setQFout(NULL);
@@ -812,7 +815,7 @@ PrintQueryTuples(const PGresult *results)
812815
pset.gfname = NULL;
813816
}
814817
else
815-
printQuery(results, &pset.popt, pset.queryFout);
818+
printQuery(results, &my_popt, pset.queryFout);
816819

817820
return true;
818821
}
@@ -1001,7 +1004,7 @@ SendQuery(const char *query)
10011004
if (on_error_rollback_warning == false && pset.sversion < 80000)
10021005
{
10031006
fprintf(stderr, _("The server version (%d) does not support savepoints for ON_ERROR_ROLLBACK.\n"),
1004-
pset.sversion);
1007+
pset.sversion);
10051008
on_error_rollback_warning = true;
10061009
}
10071010
else

src/bin/psql/common.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/common.h,v 1.43 2005/05/30 18:28:11 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/common.h,v 1.44 2005/06/13 06:36:22 neilc Exp $
77
*/
88
#ifndef COMMON_H
99
#define COMMON_H
@@ -22,7 +22,6 @@
2222

2323
#define atooid(x) ((Oid) strtoul((x), NULL, 10))
2424

25-
2625
/*
2726
* Safer versions of some standard C library functions. If an
2827
* out-of-memory condition occurs, these functions will bail out
@@ -36,7 +35,7 @@ extern void *pg_calloc(size_t nmemb, size_t size);
3635
extern bool setQFout(const char *fname);
3736

3837
extern void
39-
psql_error(const char *fmt,...)
38+
psql_error(const char *fmt, ...)
4039
/* This lets gcc check the format string for consistency. */
4140
__attribute__((format(printf, 1, 2)));
4241

src/bin/psql/print.c

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.57 2005/06/09 18:40:06 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.58 2005/06/13 06:36:22 neilc Exp $
77
*/
88
#include "postgres_fe.h"
99
#include "common.h"
@@ -29,7 +29,6 @@
2929

3030
#include "mbprint.h"
3131

32-
3332
/*************************/
3433
/* Unaligned text */
3534
/*************************/
@@ -1261,6 +1260,7 @@ printTable(const char *title,
12611260
const char *default_footer[] = {NULL};
12621261
unsigned short int border = opt->border;
12631262
FILE *output;
1263+
bool use_expanded;
12641264

12651265
if (opt->format == PRINT_NOTHING)
12661266
return;
@@ -1271,6 +1271,16 @@ printTable(const char *title,
12711271
if (opt->format != PRINT_HTML && border > 2)
12721272
border = 2;
12731273

1274+
/*
1275+
* We only want to display the results in "expanded" format if
1276+
* this is a normal (user-submitted) query, not a table we're
1277+
* printing for a slash command.
1278+
*/
1279+
if (opt->expanded && opt->normal_query)
1280+
use_expanded = true;
1281+
else
1282+
use_expanded = false;
1283+
12741284
if (fout == stdout)
12751285
{
12761286
int col_count = 0,
@@ -1305,37 +1315,56 @@ printTable(const char *title,
13051315
switch (opt->format)
13061316
{
13071317
case PRINT_UNALIGNED:
1308-
if (opt->expanded)
1309-
print_unaligned_vertical(title, headers, cells, footers, opt->fieldSep, opt->recordSep, opt->tuples_only, output);
1318+
if (use_expanded)
1319+
print_unaligned_vertical(title, headers, cells, footers,
1320+
opt->fieldSep, opt->recordSep,
1321+
opt->tuples_only, output);
13101322
else
1311-
print_unaligned_text(title, headers, cells, footers, opt->fieldSep, opt->recordSep, opt->tuples_only, output);
1323+
print_unaligned_text(title, headers, cells, footers,
1324+
opt->fieldSep, opt->recordSep,
1325+
opt->tuples_only, output);
13121326
break;
13131327
case PRINT_ALIGNED:
1314-
if (opt->expanded)
1315-
print_aligned_vertical(title, headers, cells, footers, opt->tuples_only, border, opt->encoding, output);
1328+
if (use_expanded)
1329+
print_aligned_vertical(title, headers, cells, footers,
1330+
opt->tuples_only, border,
1331+
opt->encoding, output);
13161332
else
1317-
print_aligned_text(title, headers, cells, footers, align, opt->tuples_only, border, opt->encoding, output);
1333+
print_aligned_text(title, headers, cells, footers,
1334+
align, opt->tuples_only,
1335+
border, opt->encoding, output);
13181336
break;
13191337
case PRINT_HTML:
1320-
if (opt->expanded)
1321-
print_html_vertical(title, headers, cells, footers, align, opt->tuples_only, border, opt->tableAttr, output);
1338+
if (use_expanded)
1339+
print_html_vertical(title, headers, cells, footers,
1340+
align, opt->tuples_only,
1341+
border, opt->tableAttr, output);
13221342
else
1323-
print_html_text(title, headers, cells, footers, align, opt->tuples_only, border, opt->tableAttr, output);
1343+
print_html_text(title, headers, cells, footers,
1344+
align, opt->tuples_only, border,
1345+
opt->tableAttr, output);
13241346
break;
13251347
case PRINT_LATEX:
1326-
if (opt->expanded)
1327-
print_latex_vertical(title, headers, cells, footers, align, opt->tuples_only, border, output);
1348+
if (use_expanded)
1349+
print_latex_vertical(title, headers, cells, footers, align,
1350+
opt->tuples_only, border, output);
13281351
else
1329-
print_latex_text(title, headers, cells, footers, align, opt->tuples_only, border, output);
1352+
print_latex_text(title, headers, cells, footers, align,
1353+
opt->tuples_only, border, output);
13301354
break;
13311355
case PRINT_TROFF_MS:
1332-
if (opt->expanded)
1333-
print_troff_ms_vertical(title, headers, cells, footers, align, opt->tuples_only, border, output);
1356+
if (use_expanded)
1357+
print_troff_ms_vertical(title, headers, cells, footers,
1358+
align, opt->tuples_only,
1359+
border, output);
13341360
else
1335-
print_troff_ms_text(title, headers, cells, footers, align, opt->tuples_only, border, output);
1361+
print_troff_ms_text(title, headers, cells, footers,
1362+
align, opt->tuples_only,
1363+
border, output);
13361364
break;
13371365
default:
1338-
fprintf(stderr, "+ Oops, you shouldn't see this!\n");
1366+
fprintf(stderr, _("illegal output format: %d"), opt->format);
1367+
exit(EXIT_FAILURE);
13391368
}
13401369

13411370
/* Only close if we used the pager */

src/bin/psql/print.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/print.h,v 1.23 2005/06/09 15:27:27 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/print.h,v 1.24 2005/06/13 06:36:22 neilc Exp $
77
*/
88
#ifndef PRINT_H
99
#define PRINT_H
@@ -42,6 +42,9 @@ typedef struct _printTableOpt
4242
* mode */
4343
char *tableAttr; /* attributes for HTML <table ...> */
4444
int encoding; /* character encoding */
45+
bool normal_query; /* are we presenting the results of a
46+
* "normal" query, or a slash
47+
* command? */
4548
} printTableOpt;
4649

4750

src/bin/psql/startup.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.115 2005/04/29 14:30:11 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.116 2005/06/13 06:36:22 neilc Exp $
77
*/
88
#include "postgres_fe.h"
99

@@ -143,6 +143,7 @@ main(int argc, char *argv[])
143143
pset.queryFout = stdout;
144144
pset.popt.topt.border = 1;
145145
pset.popt.topt.pager = 1;
146+
pset.popt.topt.normal_query = false;
146147
pset.popt.default_footer = true;
147148

148149
SetVariable(pset.vars, "VERSION", PG_VERSION_STR);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy