Re: [Fwd: Re: proposal: new long psql parameter --on-error-stop]

Started by Pavel Stehuleover 11 years ago43 messages
#1Pavel Stehule
pavel.stehule@gmail.com
1 attachment(s)

Hello

third version with Erik's update

Thanks Erik

Regards

Pavel

2014-06-22 12:01 GMT+02:00 Erik Rijkers <er@xs4all.nl>:

Show quoted text

Hi Pavel,

It seems you overlooked the patch that I sent?

There are some typo's in your patch (also in v2) like:

PROPMPT1, PROPMT2, PROPMPT3

SIGLELINE

I fixed those in my patch and improved the text.
Attached is the diff against your v1 patch

Thanks,

Erik

---------------------------------------------------- Original Message
-----------------------------------------------------
Subject: Re: [HACKERS] proposal: new long psql parameter --on-error-stop
From: "Erik Rijkers" <er@xs4all.nl>
Date: Sun, June 22, 2014 01:33
To: "Pavel Stehule" <pavel.stehule@gmail.com>
Cc: "MauMau" <maumau307@gmail.com>
"Andrew Dunstan" <andrew@dunslane.net>
"Tom Lane" <tgl@sss.pgh.pa.us>
Fabrízio Mello <fabriziomello@gmail.com>
"PostgreSQL Hackers" <pgsql-hackers@postgresql.org>

---------------------------------------------------------------------------------------------------------------------------

On Sun, June 22, 2014 00:10, Pavel Stehule wrote:

[help-variables-01.patch ]

+1. This patch is a very useful improvement, IMHO.

I edited the text somewhat; and removed some obvious typos.

thanks,

Erik Rijkers
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Attachments:

help-variables-03.patchtext/x-patch; charset=US-ASCII; name=help-variables-03.patchDownload
commit 2d44ee1f1bf7f7b57e51522dca88b9f55b308e67
Author: Pavel Stehule <pavel.stehule@gmail.com>
Date:   Sun Jun 22 00:08:24 2014 +0200

    show a list of psql internal, psql formatting and system variables used by psql

diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c
index 3aa3c16..7b026af 100644
--- a/src/bin/psql/help.c
+++ b/src/bin/psql/help.c
@@ -78,12 +78,13 @@ usage(void)
 	printf(_("  -f, --file=FILENAME      execute commands from file, then exit\n"));
 	printf(_("  -l, --list               list available databases, then exit\n"));
 	printf(_("  -v, --set=, --variable=NAME=VALUE\n"
-			 "                           set psql variable NAME to VALUE\n"));
+			 "                           set psql variable NAME to VALUE e.g.: -v ON_ERROR_STOP=1\n"));
 	printf(_("  -V, --version            output version information, then exit\n"));
 	printf(_("  -X, --no-psqlrc          do not read startup file (~/.psqlrc)\n"));
 	printf(_("  -1 (\"one\"), --single-transaction\n"
 			 "                           execute as a single transaction (if non-interactive)\n"));
 	printf(_("  -?, --help               show this help, then exit\n"));
+	printf(_("  --help-variables         list of available configuration variables (options), then exit\n"));
 
 	printf(_("\nInput and output options:\n"));
 	printf(_("  -a, --echo-all           echo all input from script\n"));
@@ -279,6 +280,81 @@ slashUsage(unsigned short int pager)
 }
 
 
+/*
+ * show list of available variables (options) from command line
+ */
+void
+help_variables(void)
+{
+	printf(_("List of variables (options) for use from command line.\n"));
+
+	printf(_("psql variables:\n"));
+	printf(_("Usage:\n"));
+	printf(_("  psql --set=NAME=VALUE\n  or \\set NAME VALUE in interactive mode\n\n"));
+
+	printf(_("  AUTOCOMMIT         successful SQL commands are automatically committed\n"));
+	printf(_("  COMP_KEYWORD_CASE  determines which letter case to use when completing an SQL key word\n"));
+	printf(_("  DBNAME             name of currently connected database\n"));
+	printf(_("  ECHO               write all input lines to standard output\n"));
+	printf(_("  ECHO_HIDDEN        display internal queries (same as -E option)\n"));
+	printf(_("  ENCODING           current client character set encoding\n"));
+	printf(_("  FETCH_COUNT        this many rows at a time (use less memory) (default 0 unlimited)\n"));
+	printf(_("  HISTCONTROL        when set, controls history list [ignorespace, ignoredups, ignoreboth]\n"));
+	printf(_("  HISTFILE           file name used to store the history list\n"));
+	printf(_("  HISTSIZE           the number of commands to store in the command history\n"));
+	printf(_("  HOST               the currently connected database server\n"));
+	printf(_("  IGNOREEOF          if unset, sending an EOF to interactive session terminates application\n"));
+	printf(_("  LASTOID            the value of last affected OID\n"));
+	printf(_("  ON_ERROR_ROLLBACK  when on, ROLLBACK on error\n"));
+	printf(_("  ON_ERROR_STOP      stop batch execution after error\n"));
+	printf(_("  PORT               the database server port\n"));
+	printf(_("  PROMPT1, PROMPT2, PROMPT3  specify the psql prompt\n"));
+	printf(_("  QUIET              run quietly (same as -q option)\n"));
+	printf(_("  SINGLELINE         end of line terminates SQL command mode (same as -S option)\n"));
+	printf(_("  SINGLESTEP         confirm each query mode (same as -s option)\n"));
+	printf(_("  USER               the database user currently connected\n"));
+	printf(_("  VERBOSITY          control verbosity of error reports [default, verbose, terse]\n"));
+
+	printf(_("\nPrinting options:\n"));
+	printf(_("Usage:\n"));
+	printf(_("  psql --pset=NAME[=VALUE]\n  or \\pset NAME [VALUE] in interactive mode\n\n"));
+
+	printf(_("  border             border style (number)\n"));
+	printf(_("  fieldsep           field separator for unaligned output (default '|')\n"));
+	printf(_("  fieldsep_zero      set field separator in unaligned mode to zero\n"));
+	printf(_("  format             set output format [unaligned, aligned, wrapped, html, latex, ..]\n"));
+	printf(_("  linestyle          sets the border line drawing style [ascii, old-ascii, unicode]\n"));
+	printf(_("  null               sets the string to be printed in place of a null value\n"));
+	printf(_("  pager              when the pager option is off, the pager program is not used\n"));
+	printf(_("  recordsep          specifies the record (line) separator to use in unaligned output format\n"));
+	printf(_("  recordsep_zero     record separator be in unaligned output format a zero byte\n"));
+	printf(_("  title              sets the table title for any subsequently printed tables\n"));
+	printf(_("  tuples_only        in tuples-only mode, only actual table data is shown\n"));
+
+	printf(_("\nEnvironment options:\n"));
+	printf(_("Usage:\n"));
+	printf(_("  NAME=VALUE [NAME=VALUE] psql ...\n  or \\setenv NAME [VALUE] in interactive mode\n\n"));
+
+	printf(_("  COLUMNS            number of columns for wrapped format\n"));
+	printf(_("  PAGER              used pager\n"));
+	printf(_("  PGDATABASE         same as the dbname connection parameter\n"));
+	printf(_("  PGHOST             same as the host connection parameter\n"));
+        printf(_("  PGPORT             same as the port connection parameter\n"));
+	printf(_("  PGUSER             same as the user connection parameter\n"));
+	printf(_("  PGPASSWORD         possibility to set password (not recommended)\n"));
+	printf(_("  PGPASSFILE         password file (default ~/.pgpass)\n"));
+	printf(_("  PSQL_EDITOR, EDITOR, VISUAL  editor used by \\e \\ef commands\n"));
+	printf(_("  PSQL_EDITOR_LINE_NUMBER_ARG  style how line number is used in editor\n"));
+	printf(_("  PSQL_HISTORY       alternative location for the command history file\n"));
+	printf(_("  PSQL_RC            alternative location of the user's .psqlrc file\n"));
+	printf(_("  SHELL              command executed by the \\! command\n"));
+	printf(_("  TMPDIR             directory for storing temporary files\n"));
+
+	printf(_("\nFor more information consult the psql section in the PostgreSQL\n"
+			 "documentation.\n\n"));
+	printf(_("Report bugs to <pgsql-bugs@postgresql.org>.\n"));
+}
+
 
 /*
  * helpSQL -- help with SQL commands
diff --git a/src/bin/psql/help.h b/src/bin/psql/help.h
index 054d5a4..e7affff 100644
--- a/src/bin/psql/help.h
+++ b/src/bin/psql/help.h
@@ -12,6 +12,8 @@ void		usage(void);
 
 void		slashUsage(unsigned short int pager);
 
+void		help_variables(void);
+
 void		helpSQL(const char *topic, unsigned short int pager);
 
 void		print_copyright(void);
diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c
index 45653a1..d911159 100644
--- a/src/bin/psql/startup.c
+++ b/src/bin/psql/startup.c
@@ -383,6 +383,7 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
 		{"expanded", no_argument, NULL, 'x'},
 		{"no-psqlrc", no_argument, NULL, 'X'},
 		{"help", no_argument, NULL, '?'},
+		{"help-variables", no_argument, NULL, 1},
 		{NULL, 0, NULL, 0}
 	};
 
@@ -566,6 +567,9 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
 					exit(EXIT_FAILURE);
 				}
 				break;
+			case 1:
+				help_variables();
+				exit(EXIT_SUCCESS);
 			default:
 				fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
 						pset.progname);
#2Fujii Masao
masao.fujii@gmail.com
In reply to: Pavel Stehule (#1)

On Mon, Jun 23, 2014 at 12:04 AM, Pavel Stehule <pavel.stehule@gmail.com> wrote:

Hello

third version with Erik's update

Here are some my comments:

The document of psql needs to be updated. At least the description of new option
this patch adds needs to be added into the document.

+ printf(_(" --help-variables list of available
configuration variables (options), then exit\n"));

We should get rid of "of" from the message, or add "show" in front of "list of"?

+ printf(_(" ECHO write all input lines to standard
output\n"));

This message seems not to be correct when ECHO=queries is set.

+    printf(_("  COMP_KEYWORD_CASE  determines which letter case to
use when completing an SQL key word\n"));
+    printf(_("  DBNAME             name of currently connected database\n"));
+    printf(_("  ECHO               write all input lines to standard
output\n"));

I found that some help message line uses a normal form of a verb, but
other does not.
We should standardize them?

+ printf(_(" PROMPT1, PROMPT2, PROMPT3 specify the psql prompt\n"));

When the option name field is long, we should add a new line just
after the name field
and align the starting position of the option explanation field. That is,
for example, the above should be

printf(_(" PROMPT1, PROMPT2, PROMPT3\n"
" specify the psql prompt\n"));

+ printf(_(" ON_ERROR_ROLLBACK when on, ROLLBACK on error\n"));

This message seems incorrect to me. When this option is on and an error occurs
in transaction, transaction continues rather than ROLLBACK occurs, IIUC.
I did not check whole help messages yet, but ISTM some messages are not correct.
It's better to check them again.

+ printf(_(" PSQL_RC alternative location of the user's
.psqlrc file\n"));

Typo: PSQL_RC should be PSQLRC

+    printf(_("  PGDATABASE         same as the dbname connection
parameter\n"));
+    printf(_("  PGHOST             same as the host connection parameter\n"));
+        printf(_("  PGPORT             same as the port connection
parameter\n"));
+    printf(_("  PGUSER             same as the user connection parameter\n"));
+    printf(_("  PGPASSWORD         possibility to set password (not
recommended)\n"));
+    printf(_("  PGPASSFILE         password file (default ~/.pgpass)\n"));

I don't think that psql needs to display the help messages of even environment
variables supported by libpq.

Regards,

--
Fujii Masao

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#3Pavel Stehule
pavel.stehule@gmail.com
In reply to: Fujii Masao (#2)

Hello

2014-06-23 10:02 GMT+02:00 Fujii Masao <masao.fujii@gmail.com>:

On Mon, Jun 23, 2014 at 12:04 AM, Pavel Stehule <pavel.stehule@gmail.com>
wrote:

Hello

third version with Erik's update

Here are some my comments:

The document of psql needs to be updated. At least the description of new
option
this patch adds needs to be added into the document.

+ printf(_(" --help-variables list of available
configuration variables (options), then exit\n"));

We should get rid of "of" from the message, or add "show" in front of
"list of"?

+ printf(_(" ECHO write all input lines to standard
output\n"));

This message seems not to be correct when ECHO=queries is set.

+    printf(_("  COMP_KEYWORD_CASE  determines which letter case to
use when completing an SQL key word\n"));
+    printf(_("  DBNAME             name of currently connected
database\n"));
+    printf(_("  ECHO               write all input lines to standard
output\n"));

I found that some help message line uses a normal form of a verb, but
other does not.
We should standardize them?

+ printf(_(" PROMPT1, PROMPT2, PROMPT3 specify the psql prompt\n"));

When the option name field is long, we should add a new line just
after the name field
and align the starting position of the option explanation field. That is,
for example, the above should be

printf(_(" PROMPT1, PROMPT2, PROMPT3\n"
" specify the psql prompt\n"));

+ printf(_(" ON_ERROR_ROLLBACK when on, ROLLBACK on error\n"));

This message seems incorrect to me. When this option is on and an error
occurs
in transaction, transaction continues rather than ROLLBACK occurs, IIUC.
I did not check whole help messages yet, but ISTM some messages are not
correct.
It's better to check them again.

+ printf(_(" PSQL_RC alternative location of the user's
.psqlrc file\n"));

Typo: PSQL_RC should be PSQLRC

+    printf(_("  PGDATABASE         same as the dbname connection
parameter\n"));
+    printf(_("  PGHOST             same as the host connection
parameter\n"));
+        printf(_("  PGPORT             same as the port connection
parameter\n"));
+    printf(_("  PGUSER             same as the user connection
parameter\n"));
+    printf(_("  PGPASSWORD         possibility to set password (not
recommended)\n"));
+    printf(_("  PGPASSFILE         password file (default ~/.pgpass)\n"));

I don't think that psql needs to display the help messages of even
environment
variables supported by libpq.

Main reason is a PGPASSWORD -- it is probably most used env variable with
psql

PGPASSWORD=****** psql is very often used pattern

Regards

Pavel Stehule

Show quoted text

Regards,

--
Fujii Masao

#4Fujii Masao
masao.fujii@gmail.com
In reply to: Pavel Stehule (#3)

On Mon, Jun 23, 2014 at 5:10 PM, Pavel Stehule <pavel.stehule@gmail.com> wrote:

Hello

2014-06-23 10:02 GMT+02:00 Fujii Masao <masao.fujii@gmail.com>:

On Mon, Jun 23, 2014 at 12:04 AM, Pavel Stehule <pavel.stehule@gmail.com>
wrote:

Hello

third version with Erik's update

Here are some my comments:

The document of psql needs to be updated. At least the description of new
option
this patch adds needs to be added into the document.

+ printf(_(" --help-variables list of available
configuration variables (options), then exit\n"));

We should get rid of "of" from the message, or add "show" in front of
"list of"?

+ printf(_(" ECHO write all input lines to standard
output\n"));

This message seems not to be correct when ECHO=queries is set.

+    printf(_("  COMP_KEYWORD_CASE  determines which letter case to
use when completing an SQL key word\n"));
+    printf(_("  DBNAME             name of currently connected
database\n"));
+    printf(_("  ECHO               write all input lines to standard
output\n"));

I found that some help message line uses a normal form of a verb, but
other does not.
We should standardize them?

+ printf(_(" PROMPT1, PROMPT2, PROMPT3 specify the psql prompt\n"));

When the option name field is long, we should add a new line just
after the name field
and align the starting position of the option explanation field. That is,
for example, the above should be

printf(_(" PROMPT1, PROMPT2, PROMPT3\n"
" specify the psql prompt\n"));

+ printf(_(" ON_ERROR_ROLLBACK when on, ROLLBACK on error\n"));

This message seems incorrect to me. When this option is on and an error
occurs
in transaction, transaction continues rather than ROLLBACK occurs, IIUC.
I did not check whole help messages yet, but ISTM some messages are not
correct.
It's better to check them again.

+ printf(_(" PSQL_RC alternative location of the user's
.psqlrc file\n"));

Typo: PSQL_RC should be PSQLRC

+    printf(_("  PGDATABASE         same as the dbname connection
parameter\n"));
+    printf(_("  PGHOST             same as the host connection
parameter\n"));
+        printf(_("  PGPORT             same as the port connection
parameter\n"));
+    printf(_("  PGUSER             same as the user connection
parameter\n"));
+    printf(_("  PGPASSWORD         possibility to set password (not
recommended)\n"));
+    printf(_("  PGPASSFILE         password file (default
~/.pgpass)\n"));

I don't think that psql needs to display the help messages of even
environment
variables supported by libpq.

Main reason is a PGPASSWORD -- it is probably most used env variable with
psql

PGPASSWORD=****** psql is very often used pattern

But it's not recommended as the help message which the patch added says ;)

Regards,

--
Fujii Masao

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#5Pavel Stehule
pavel.stehule@gmail.com
In reply to: Fujii Masao (#4)

2014-06-23 10:57 GMT+02:00 Fujii Masao <masao.fujii@gmail.com>:

On Mon, Jun 23, 2014 at 5:10 PM, Pavel Stehule <pavel.stehule@gmail.com>
wrote:

Hello

2014-06-23 10:02 GMT+02:00 Fujii Masao <masao.fujii@gmail.com>:

On Mon, Jun 23, 2014 at 12:04 AM, Pavel Stehule <

pavel.stehule@gmail.com>

wrote:

Hello

third version with Erik's update

Here are some my comments:

The document of psql needs to be updated. At least the description of

new

option
this patch adds needs to be added into the document.

+ printf(_(" --help-variables list of available
configuration variables (options), then exit\n"));

We should get rid of "of" from the message, or add "show" in front of
"list of"?

+ printf(_(" ECHO write all input lines to standard
output\n"));

This message seems not to be correct when ECHO=queries is set.

+    printf(_("  COMP_KEYWORD_CASE  determines which letter case to
use when completing an SQL key word\n"));
+    printf(_("  DBNAME             name of currently connected
database\n"));
+    printf(_("  ECHO               write all input lines to standard
output\n"));

I found that some help message line uses a normal form of a verb, but
other does not.
We should standardize them?

+ printf(_(" PROMPT1, PROMPT2, PROMPT3 specify the psql

prompt\n"));

When the option name field is long, we should add a new line just
after the name field
and align the starting position of the option explanation field. That

is,

for example, the above should be

printf(_(" PROMPT1, PROMPT2, PROMPT3\n"
" specify the psql prompt\n"));

+ printf(_(" ON_ERROR_ROLLBACK when on, ROLLBACK on error\n"));

This message seems incorrect to me. When this option is on and an error
occurs
in transaction, transaction continues rather than ROLLBACK occurs, IIUC.
I did not check whole help messages yet, but ISTM some messages are not
correct.
It's better to check them again.

+ printf(_(" PSQL_RC alternative location of the user's
.psqlrc file\n"));

Typo: PSQL_RC should be PSQLRC

+    printf(_("  PGDATABASE         same as the dbname connection
parameter\n"));
+    printf(_("  PGHOST             same as the host connection
parameter\n"));
+        printf(_("  PGPORT             same as the port connection
parameter\n"));
+    printf(_("  PGUSER             same as the user connection
parameter\n"));
+    printf(_("  PGPASSWORD         possibility to set password (not
recommended)\n"));
+    printf(_("  PGPASSFILE         password file (default
~/.pgpass)\n"));

I don't think that psql needs to display the help messages of even
environment
variables supported by libpq.

Main reason is a PGPASSWORD -- it is probably most used env variable with
psql

PGPASSWORD=****** psql is very often used pattern

But it's not recommended as the help message which the patch added says ;)

why?

who can see this value?

regards

Pavel

Show quoted text

Regards,

--
Fujii Masao

#6Fujii Masao
masao.fujii@gmail.com
In reply to: Pavel Stehule (#5)

On Mon, Jun 23, 2014 at 6:06 PM, Pavel Stehule <pavel.stehule@gmail.com> wrote:

2014-06-23 10:57 GMT+02:00 Fujii Masao <masao.fujii@gmail.com>:

On Mon, Jun 23, 2014 at 5:10 PM, Pavel Stehule <pavel.stehule@gmail.com>
wrote:

Hello

2014-06-23 10:02 GMT+02:00 Fujii Masao <masao.fujii@gmail.com>:

On Mon, Jun 23, 2014 at 12:04 AM, Pavel Stehule
<pavel.stehule@gmail.com>
wrote:

Hello

third version with Erik's update

Here are some my comments:

The document of psql needs to be updated. At least the description of
new
option
this patch adds needs to be added into the document.

+ printf(_(" --help-variables list of available
configuration variables (options), then exit\n"));

We should get rid of "of" from the message, or add "show" in front of
"list of"?

+ printf(_(" ECHO write all input lines to standard
output\n"));

This message seems not to be correct when ECHO=queries is set.

+    printf(_("  COMP_KEYWORD_CASE  determines which letter case to
use when completing an SQL key word\n"));
+    printf(_("  DBNAME             name of currently connected
database\n"));
+    printf(_("  ECHO               write all input lines to standard
output\n"));

I found that some help message line uses a normal form of a verb, but
other does not.
We should standardize them?

+ printf(_(" PROMPT1, PROMPT2, PROMPT3 specify the psql
prompt\n"));

When the option name field is long, we should add a new line just
after the name field
and align the starting position of the option explanation field. That
is,
for example, the above should be

printf(_(" PROMPT1, PROMPT2, PROMPT3\n"
" specify the psql prompt\n"));

+ printf(_(" ON_ERROR_ROLLBACK when on, ROLLBACK on error\n"));

This message seems incorrect to me. When this option is on and an error
occurs
in transaction, transaction continues rather than ROLLBACK occurs,
IIUC.
I did not check whole help messages yet, but ISTM some messages are not
correct.
It's better to check them again.

+ printf(_(" PSQL_RC alternative location of the user's
.psqlrc file\n"));

Typo: PSQL_RC should be PSQLRC

+    printf(_("  PGDATABASE         same as the dbname connection
parameter\n"));
+    printf(_("  PGHOST             same as the host connection
parameter\n"));
+        printf(_("  PGPORT             same as the port connection
parameter\n"));
+    printf(_("  PGUSER             same as the user connection
parameter\n"));
+    printf(_("  PGPASSWORD         possibility to set password (not
recommended)\n"));
+    printf(_("  PGPASSFILE         password file (default
~/.pgpass)\n"));

I don't think that psql needs to display the help messages of even
environment
variables supported by libpq.

Main reason is a PGPASSWORD -- it is probably most used env variable
with
psql

PGPASSWORD=****** psql is very often used pattern

But it's not recommended as the help message which the patch added says ;)

why?

who can see this value?

I'm sure that the document explains this.

http://www.postgresql.org/docs/devel/static/libpq-envars.html
---------------------------------------
PGPASSWORD behaves the same as the password connection parameter.
Use of this environment variable is not recommended for security reasons,
as some operating systems allow non-root users to see process environment
variables via ps; instead consider using the ~/.pgpass file
---------------------------------------

Regards,

--
Fujii Masao

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#7Pavel Stehule
pavel.stehule@gmail.com
In reply to: Fujii Masao (#6)

2014-06-23 11:53 GMT+02:00 Fujii Masao <masao.fujii@gmail.com>:

On Mon, Jun 23, 2014 at 6:06 PM, Pavel Stehule <pavel.stehule@gmail.com>
wrote:

2014-06-23 10:57 GMT+02:00 Fujii Masao <masao.fujii@gmail.com>:

On Mon, Jun 23, 2014 at 5:10 PM, Pavel Stehule <pavel.stehule@gmail.com

wrote:

Hello

2014-06-23 10:02 GMT+02:00 Fujii Masao <masao.fujii@gmail.com>:

On Mon, Jun 23, 2014 at 12:04 AM, Pavel Stehule
<pavel.stehule@gmail.com>
wrote:

Hello

third version with Erik's update

Here are some my comments:

The document of psql needs to be updated. At least the description of
new
option
this patch adds needs to be added into the document.

+ printf(_(" --help-variables list of available
configuration variables (options), then exit\n"));

We should get rid of "of" from the message, or add "show" in front of
"list of"?

+ printf(_(" ECHO write all input lines to standard
output\n"));

This message seems not to be correct when ECHO=queries is set.

+    printf(_("  COMP_KEYWORD_CASE  determines which letter case to
use when completing an SQL key word\n"));
+    printf(_("  DBNAME             name of currently connected
database\n"));
+    printf(_("  ECHO               write all input lines to standard
output\n"));

I found that some help message line uses a normal form of a verb, but
other does not.
We should standardize them?

+ printf(_(" PROMPT1, PROMPT2, PROMPT3 specify the psql
prompt\n"));

When the option name field is long, we should add a new line just
after the name field
and align the starting position of the option explanation field. That
is,
for example, the above should be

printf(_(" PROMPT1, PROMPT2, PROMPT3\n"
" specify the psql prompt\n"));

+ printf(_(" ON_ERROR_ROLLBACK when on, ROLLBACK on error\n"));

This message seems incorrect to me. When this option is on and an

error

occurs
in transaction, transaction continues rather than ROLLBACK occurs,
IIUC.
I did not check whole help messages yet, but ISTM some messages are

not

correct.
It's better to check them again.

+ printf(_(" PSQL_RC alternative location of the

user's

.psqlrc file\n"));

Typo: PSQL_RC should be PSQLRC

+    printf(_("  PGDATABASE         same as the dbname connection
parameter\n"));
+    printf(_("  PGHOST             same as the host connection
parameter\n"));
+        printf(_("  PGPORT             same as the port connection
parameter\n"));
+    printf(_("  PGUSER             same as the user connection
parameter\n"));
+    printf(_("  PGPASSWORD         possibility to set password (not
recommended)\n"));
+    printf(_("  PGPASSFILE         password file (default
~/.pgpass)\n"));

I don't think that psql needs to display the help messages of even
environment
variables supported by libpq.

Main reason is a PGPASSWORD -- it is probably most used env variable
with
psql

PGPASSWORD=****** psql is very often used pattern

But it's not recommended as the help message which the patch added says

;)

why?

who can see this value?

I'm sure that the document explains this.

ok

I am too Linux centrist :( it is safe there and I don't see a others

Thank you for info

Regards

Pavel

Show quoted text

http://www.postgresql.org/docs/devel/static/libpq-envars.html
---------------------------------------
PGPASSWORD behaves the same as the password connection parameter.
Use of this environment variable is not recommended for security reasons,
as some operating systems allow non-root users to see process environment
variables via ps; instead consider using the ~/.pgpass file
---------------------------------------

Regards,

--
Fujii Masao

#8Pavel Stehule
pavel.stehule@gmail.com
In reply to: Fujii Masao (#2)
1 attachment(s)

Hello

I am sending little bit modified patch by Fujii' comments - but I am not
able to fix it more - it is task for someone with better English skill then
I have

Regards

Pavel

2014-06-23 10:02 GMT+02:00 Fujii Masao <masao.fujii@gmail.com>:

Show quoted text

On Mon, Jun 23, 2014 at 12:04 AM, Pavel Stehule <pavel.stehule@gmail.com>
wrote:

Hello

third version with Erik's update

Here are some my comments:

The document of psql needs to be updated. At least the description of new
option
this patch adds needs to be added into the document.

+ printf(_(" --help-variables list of available
configuration variables (options), then exit\n"));

We should get rid of "of" from the message, or add "show" in front of
"list of"?

+ printf(_(" ECHO write all input lines to standard
output\n"));

This message seems not to be correct when ECHO=queries is set.

+    printf(_("  COMP_KEYWORD_CASE  determines which letter case to
use when completing an SQL key word\n"));
+    printf(_("  DBNAME             name of currently connected
database\n"));
+    printf(_("  ECHO               write all input lines to standard
output\n"));

I found that some help message line uses a normal form of a verb, but
other does not.
We should standardize them?

+ printf(_(" PROMPT1, PROMPT2, PROMPT3 specify the psql prompt\n"));

When the option name field is long, we should add a new line just
after the name field
and align the starting position of the option explanation field. That is,
for example, the above should be

printf(_(" PROMPT1, PROMPT2, PROMPT3\n"
" specify the psql prompt\n"));

+ printf(_(" ON_ERROR_ROLLBACK when on, ROLLBACK on error\n"));

This message seems incorrect to me. When this option is on and an error
occurs
in transaction, transaction continues rather than ROLLBACK occurs, IIUC.
I did not check whole help messages yet, but ISTM some messages are not
correct.
It's better to check them again.

+ printf(_(" PSQL_RC alternative location of the user's
.psqlrc file\n"));

Typo: PSQL_RC should be PSQLRC

+    printf(_("  PGDATABASE         same as the dbname connection
parameter\n"));
+    printf(_("  PGHOST             same as the host connection
parameter\n"));
+        printf(_("  PGPORT             same as the port connection
parameter\n"));
+    printf(_("  PGUSER             same as the user connection
parameter\n"));
+    printf(_("  PGPASSWORD         possibility to set password (not
recommended)\n"));
+    printf(_("  PGPASSFILE         password file (default ~/.pgpass)\n"));

I don't think that psql needs to display the help messages of even
environment
variables supported by libpq.

Regards,

--
Fujii Masao

Attachments:

help-variables-04.patchtext/x-patch; charset=US-ASCII; name=help-variables-04.patchDownload
commit 4d8a267870f15a22818da226f72223db86944636
Author: Pavel Stehule <pavel.stehule@gooddata.com>
Date:   Mon Jun 23 19:38:41 2014 +0200

    without comments

diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c
index 3aa3c16..e960f34 100644
--- a/src/bin/psql/help.c
+++ b/src/bin/psql/help.c
@@ -78,12 +78,13 @@ usage(void)
 	printf(_("  -f, --file=FILENAME      execute commands from file, then exit\n"));
 	printf(_("  -l, --list               list available databases, then exit\n"));
 	printf(_("  -v, --set=, --variable=NAME=VALUE\n"
-			 "                           set psql variable NAME to VALUE\n"));
+			 "                           set psql variable NAME to VALUE e.g.: -v ON_ERROR_STOP=1\n"));
 	printf(_("  -V, --version            output version information, then exit\n"));
 	printf(_("  -X, --no-psqlrc          do not read startup file (~/.psqlrc)\n"));
 	printf(_("  -1 (\"one\"), --single-transaction\n"
 			 "                           execute as a single transaction (if non-interactive)\n"));
 	printf(_("  -?, --help               show this help, then exit\n"));
+	printf(_("  --help-variables         list of available configuration variables (options), then exit\n"));
 
 	printf(_("\nInput and output options:\n"));
 	printf(_("  -a, --echo-all           echo all input from script\n"));
@@ -279,6 +280,84 @@ slashUsage(unsigned short int pager)
 }
 
 
+/*
+ * show list of available variables (options) from command line
+ */
+void
+help_variables(void)
+{
+	printf(_("List of variables (options) for use from command line.\n"));
+
+	printf(_("psql variables:\n"));
+	printf(_("Usage:\n"));
+	printf(_("  psql --set=NAME=VALUE\n  or \\set NAME VALUE in interactive mode\n\n"));
+
+	printf(_("  AUTOCOMMIT         successful SQL commands are automatically committed\n"));
+	printf(_("  COMP_KEYWORD_CASE  determines which letter case to use when completing an SQL key word\n"));
+	printf(_("  DBNAME             name of currently connected database\n"));
+	printf(_("  ECHO               controls what input can be writtent to standard output [all, queries]\n"));
+	printf(_("  ECHO_HIDDEN        display internal queries (same as -E option)\n"));
+	printf(_("  ENCODING           current client character set encoding\n"));
+	printf(_("  FETCH_COUNT        fetch many rows at a time (use less memory) (default 0 unlimited)\n"));
+	printf(_("  HISTCONTROL        when set, controls history list [ignorespace, ignoredups, ignoreboth]\n"));
+	printf(_("  HISTFILE           file name used to store the history list\n"));
+	printf(_("  HISTSIZE           the number of commands to store in the command history\n"));
+	printf(_("  HOST               the currently connected database server\n"));
+	printf(_("  IGNOREEOF          if unset, sending an EOF to interactive session terminates application\n"));
+	printf(_("  LASTOID            the value of last affected OID\n"));
+	printf(_("  ON_ERROR_ROLLBACK  when on, the error doesn't break transaction (due implicit SAVEPOINs)\n"));
+	printf(_("  ON_ERROR_STOP      stop batch execution after error\n"));
+	printf(_("  PORT               the database server port\n"));
+	printf(_("  PROMPT1, PROMPT2, PROMPT3\n"
+					 "                     specify the psql prompt\n"));
+	printf(_("  QUIET              run quietly (same as -q option)\n"));
+	printf(_("  SINGLELINE         end of line terminates SQL command mode (same as -S option)\n"));
+	printf(_("  SINGLESTEP         confirm each query mode (same as -s option)\n"));
+	printf(_("  USER               the database user currently connected\n"));
+	printf(_("  VERBOSITY          control verbosity of error reports [default, verbose, terse]\n"));
+
+	printf(_("\nPrinting options:\n"));
+	printf(_("Usage:\n"));
+	printf(_("  psql --pset=NAME[=VALUE]\n  or \\pset NAME [VALUE] in interactive mode\n\n"));
+
+	printf(_("  border             border style (number)\n"));
+	printf(_("  fieldsep           field separator for unaligned output (default '|')\n"));
+	printf(_("  fieldsep_zero      set field separator in unaligned mode to zero\n"));
+	printf(_("  format             set output format [unaligned, aligned, wrapped, html, latex, ..]\n"));
+	printf(_("  linestyle          sets the border line drawing style [ascii, old-ascii, unicode]\n"));
+	printf(_("  null               sets the string to be printed in place of a null value\n"));
+	printf(_("  pager              when the pager option is off, the pager program is not used\n"));
+	printf(_("  recordsep          specifies the record (line) separator to use in unaligned output format\n"));
+	printf(_("  recordsep_zero     record separator be in unaligned output format a zero byte\n"));
+	printf(_("  title              sets the table title for any subsequently printed tables\n"));
+	printf(_("  tuples_only        in tuples-only mode, only actual table data is shown\n"));
+
+	printf(_("\nEnvironment options:\n"));
+	printf(_("Usage:\n"));
+	printf(_("  NAME=VALUE [NAME=VALUE] psql ...\n  or \\setenv NAME [VALUE] in interactive mode\n\n"));
+
+	printf(_("  COLUMNS            number of columns for wrapped format\n"));
+	printf(_("  PAGER              used pager\n"));
+	printf(_("  PGDATABASE         same as the dbname connection parameter\n"));
+	printf(_("  PGHOST             same as the host connection parameter\n"));
+	printf(_("  PGPORT             same as the port connection parameter\n"));
+	printf(_("  PGUSER             same as the user connection parameter\n"));
+	printf(_("  PGPASSWORD         possibility to set password (not recommended)\n"));
+	printf(_("  PGPASSFILE         password file (default ~/.pgpass)\n"));
+	printf(_("  PSQL_EDITOR, EDITOR, VISUAL\n"
+					 "                     editor used by \\e \\ef commands\n"));
+	printf(_("  PSQL_EDITOR_LINE_NUMBER_ARG\n"
+					 "                     style how line number is used in editor\n"));
+	printf(_("  PSQL_HISTORY       alternative location for the command history file\n"));
+	printf(_("  PSQLRC             alternative location of the user's .psqlrc file\n"));
+	printf(_("  SHELL              command executed by the \\! command\n"));
+	printf(_("  TMPDIR             directory for storing temporary files\n"));
+
+	printf(_("\nFor more information consult the psql section in the PostgreSQL\n"
+			 "documentation.\n\n"));
+	printf(_("Report bugs to <pgsql-bugs@postgresql.org>.\n"));
+}
+
 
 /*
  * helpSQL -- help with SQL commands
diff --git a/src/bin/psql/help.h b/src/bin/psql/help.h
index 054d5a4..e7affff 100644
--- a/src/bin/psql/help.h
+++ b/src/bin/psql/help.h
@@ -12,6 +12,8 @@ void		usage(void);
 
 void		slashUsage(unsigned short int pager);
 
+void		help_variables(void);
+
 void		helpSQL(const char *topic, unsigned short int pager);
 
 void		print_copyright(void);
diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c
index 45653a1..d911159 100644
--- a/src/bin/psql/startup.c
+++ b/src/bin/psql/startup.c
@@ -383,6 +383,7 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
 		{"expanded", no_argument, NULL, 'x'},
 		{"no-psqlrc", no_argument, NULL, 'X'},
 		{"help", no_argument, NULL, '?'},
+		{"help-variables", no_argument, NULL, 1},
 		{NULL, 0, NULL, 0}
 	};
 
@@ -566,6 +567,9 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
 					exit(EXIT_FAILURE);
 				}
 				break;
+			case 1:
+				help_variables();
+				exit(EXIT_SUCCESS);
 			default:
 				fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
 						pset.progname);
#9MauMau
maumau307@gmail.com
In reply to: Pavel Stehule (#8)

OK, let me help you, though I'm only a Japanese who is never confident in my
English.

(1)
As Fujii-san pointed out, could you add explanation for --help-variables in
doc/src/sgml/ref/psqlref.sgml?

(2)
+ printf(_(" --help-variables list of available configuration
variables (options), then exit\n"));

should better be:

+ printf(_(" --help-variables show A list of all specially treated
variables, then exit\n"));

This follows the psql manual page. Similarly,

+ printf(_("List of variables (options) for use from command line.\n"));

should be:

+ printf(_("List of specially treated variables.\n"));

(3)
+ printf(_(" ECHO control what input can be writtent to
standard output [all, queries]\n"));

"writtent" should be "written". "controls" should be "control" like other
options.

(4)
+ printf(_(" ECHO_HIDDEN display internal queries (same as -E
option)\n"));

should better be:

+ printf(_(" ECHO_HIDDEN display internal queries executed by
backslash commands\n"));

I think "(same as ...)" can be omitted to keep the description short. If
you want to retain it, other variables should also accompany similar
description, such as -a for ECHO.

(5)
+ printf(_(" FETCH_COUNT fetch many rows at a time (use less memory)
(default 0 unlimited)\n"));

should better be:

+ printf(_(" FETCH_COUNT the number of result rows to fetch and
display at a time (default: 0=unlimited)\n"));

(6)
+ printf(_(" HISTCONTROL when set, controls history list
[ignorespace, ignoredups, ignoreboth]\n"));

should better be:

+ printf(_(" HISTCONTROL control history list [ignorespace,
ignoredups, ignoreboth]\n"));

(7)
+ printf(_(" USER the database user currently connected\n"));

should add "as" at the end:

+ printf(_(" USER the database user currently connected
as\n"));

(8)
"Printing options" section lack the following ones described in psql manual:

columns
expanded (or x)
footer
numericlocale
tableattr (or T)

(9)
+ printf(_("\nEnvironment options:\n"));

should be ""Environment variables". And this section lacks description for
Windows, such as:

+ printf(_("  NAME=VALUE [NAME=VALUE] psql ...\n  or \\setenv NAME [VALUE] 
in interactive mode\n\n"));
+ printf(_("  PGPASSFILE         password file (default ~/.pgpass)\n"));

Regards
MauMau

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#10Pavel Stehule
pavel.stehule@gmail.com
In reply to: MauMau (#9)
1 attachment(s)

Hello

Here is next update

2014-06-25 17:17 GMT+02:00 MauMau <maumau307@gmail.com>:

OK, let me help you, though I'm only a Japanese who is never confident in
my English.

(1)
As Fujii-san pointed out, could you add explanation for --help-variables
in doc/src/sgml/ref/psqlref.sgml?

(2)

+ printf(_(" --help-variables list of available configuration
variables (options), then exit\n"));

should better be:

+ printf(_(" --help-variables show A list of all specially
treated variables, then exit\n"));

This follows the psql manual page. Similarly,

+ printf(_("List of variables (options) for use from command line.\n"));

should be:

+ printf(_("List of specially treated variables.\n"));

(3)
+ printf(_(" ECHO control what input can be writtent to
standard output [all, queries]\n"));

"writtent" should be "written". "controls" should be "control" like other
options.

(4)
+ printf(_(" ECHO_HIDDEN display internal queries (same as -E
option)\n"));

should better be:

+ printf(_(" ECHO_HIDDEN display internal queries executed by
backslash commands\n"));

I think "(same as ...)" can be omitted to keep the description short. If
you want to retain it, other variables should also accompany similar
description, such as -a for ECHO.

(5)
+ printf(_(" FETCH_COUNT fetch many rows at a time (use less
memory) (default 0 unlimited)\n"));

should better be:

+ printf(_(" FETCH_COUNT the number of result rows to fetch and
display at a time (default: 0=unlimited)\n"));

(6)
+ printf(_(" HISTCONTROL when set, controls history list
[ignorespace, ignoredups, ignoreboth]\n"));

should better be:

+ printf(_(" HISTCONTROL control history list [ignorespace,
ignoredups, ignoreboth]\n"));

(7)
+ printf(_(" USER the database user currently
connected\n"));

should add "as" at the end:

+ printf(_(" USER the database user currently connected
as\n"));

(8)
"Printing options" section lack the following ones described in psql
manual:

columns
expanded (or x)
footer
numericlocale
tableattr (or T)

fixed

(9)
+ printf(_("\nEnvironment options:\n"));

should be ""Environment variables". And this section lacks description
for Windows, such as:

+ printf(_(" NAME=VALUE [NAME=VALUE] psql ...\n or \\setenv NAME [VALUE]
in interactive mode\n\n"));

+ printf(_(" PGPASSFILE password file (default ~/.pgpass)\n"));

??? -

Regards

Pavel

Show quoted text

Regards
MauMau

Attachments:

help-variables-05.patchtext/x-patch; charset=US-ASCII; name=help-variables-05.patchDownload
commit 4d77ccf19ac77dc0f43a58f4d2b74d4aebed871d
Author: Pavel Stehule <pavel.stehule@gooddata.com>
Date:   Mon Jun 23 19:38:41 2014 +0200

    without comments

diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index ee6ec3a..6a172dc 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -556,6 +556,15 @@ EOF
       </listitem>
     </varlistentry>
 
+    <varlistentry>
+      <term><option>--help-variables</></term>
+      <listitem>
+      <para>
+      Show help about <application>psql</application> variables,
+      and exit.
+      </para>
+      </listitem>
+    </varlistentry>
   </variablelist>
  </refsect1>
 
diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c
index 3aa3c16..1304e1a 100644
--- a/src/bin/psql/help.c
+++ b/src/bin/psql/help.c
@@ -78,12 +78,13 @@ usage(void)
 	printf(_("  -f, --file=FILENAME      execute commands from file, then exit\n"));
 	printf(_("  -l, --list               list available databases, then exit\n"));
 	printf(_("  -v, --set=, --variable=NAME=VALUE\n"
-			 "                           set psql variable NAME to VALUE\n"));
+			 "                           set psql variable NAME to VALUE e.g.: -v ON_ERROR_STOP=1\n"));
 	printf(_("  -V, --version            output version information, then exit\n"));
 	printf(_("  -X, --no-psqlrc          do not read startup file (~/.psqlrc)\n"));
 	printf(_("  -1 (\"one\"), --single-transaction\n"
 			 "                           execute as a single transaction (if non-interactive)\n"));
 	printf(_("  -?, --help               show this help, then exit\n"));
+	printf(_("  --help-variables         show a list of all specially treated variables, then exit\n"));
 
 	printf(_("\nInput and output options:\n"));
 	printf(_("  -a, --echo-all           echo all input from script\n"));
@@ -279,6 +280,92 @@ slashUsage(unsigned short int pager)
 }
 
 
+/*
+ * show list of available variables (options) from command line
+ */
+void
+help_variables(void)
+{
+	printf(_("List of specially treated variables.\n"));
+
+	printf(_("psql variables:\n"));
+	printf(_("Usage:\n"));
+	printf(_("  psql --set=NAME=VALUE\n  or \\set NAME VALUE in interactive mode\n\n"));
+
+	printf(_("  AUTOCOMMIT         successful SQL commands are automatically committed\n"));
+	printf(_("  COMP_KEYWORD_CASE  determines which letter case to use when completing an SQL key word\n"));
+	printf(_("  DBNAME             name of currently connected database\n"));
+	printf(_("  ECHO               control what input can be written to standard output [all, queries]\n"));
+	printf(_("  ECHO_HIDDEN        display internal queries executed by backslash commands\n"));
+	printf(_("  ENCODING           current client character set encoding\n"));
+	printf(_("  FETCH_COUNT        the number of result rows to fetch and display at a time\n"
+					 "                     (default: 0=unlimited)\n"));
+	printf(_("  HISTCONTROL        control history list [ignorespace, ignoredups, ignoreboth]\n"));
+	printf(_("  HISTFILE           file name used to store the history list\n"));
+	printf(_("  HISTSIZE           the number of commands to store in the command history\n"));
+	printf(_("  HOST               the currently connected database server\n"));
+	printf(_("  IGNOREEOF          if unset, sending an EOF to interactive session terminates application\n"));
+	printf(_("  LASTOID            the value of last affected OID\n"));
+	printf(_("  ON_ERROR_ROLLBACK  when on, the error doesn't break transaction (due implicit SAVEPOINs)\n"));
+	printf(_("  ON_ERROR_STOP      stop batch execution after error\n"));
+	printf(_("  PORT               the database server port\n"));
+	printf(_("  PROMPT1, PROMPT2, PROMPT3\n"
+					 "                     specify the psql prompt\n"));
+	printf(_("  QUIET              run quietly (same as -q option)\n"));
+	printf(_("  SINGLELINE         end of line terminates SQL command mode (same as -S option)\n"));
+	printf(_("  SINGLESTEP         confirm each query mode (same as -s option)\n"));
+	printf(_("  USER               the database user currently connected as\n"));
+	printf(_("  VERBOSITY          control verbosity of error reports [default, verbose, terse]\n"));
+
+	printf(_("\nPrinting options:\n"));
+	printf(_("Usage:\n"));
+	printf(_("  psql --pset=NAME[=VALUE]\n  or \\pset NAME [VALUE] in interactive mode\n\n"));
+
+	printf(_("  border             border style (number)\n"));
+	printf(_("  columns            sets the target width for the wrapped format\n"));
+	printf(_("  expanded (or x)    toggle expanded output\n"));
+	printf(_("  fieldsep           field separator for unaligned output (default '|')\n"));
+	printf(_("  fieldsep_zero      set field separator in unaligned mode to zero\n"));
+	printf(_("  format             set output format [unaligned, aligned, wrapped, html, latex, ..]\n"));
+	printf(_("  footer             enable or disable display of the table foote [on, off]\n"));
+	printf(_("  linestyle          sets the border line drawing style [ascii, old-ascii, unicode]\n"));
+	printf(_("  null               sets the string to be printed in place of a null value\n"));
+	printf(_("  numericlocale      enable or disable display of a locale-specific character to separate\n"
+					 "                     groups digits [on, off]\n"));
+	printf(_("  pager              when the pager option is off, the pager program is not used\n"));
+	printf(_("  recordsep          specifies the record (line) separator to use in unaligned output format\n"));
+	printf(_("  recordsep_zero     record separator be in unaligned output format a zero byte\n"));
+	printf(_("  tableattr (or T)   specifies attributies for table tag in html format or proportional\n"
+					 "                     column width of left aligned data type in latex format\n"));
+	printf(_("  title              sets the table title for any subsequently printed tables\n"));
+	printf(_("  tuples_only        in tuples-only mode, only actual table data is shown\n"));
+
+	printf(_("\nEnvironment variables:\n"));
+	printf(_("Usage:\n"));
+	printf(_("  NAME=VALUE [NAME=VALUE] psql ...\n  or \\setenv NAME [VALUE] in interactive mode\n\n"));
+
+	printf(_("  COLUMNS            number of columns for wrapped format\n"));
+	printf(_("  PAGER              used pager\n"));
+	printf(_("  PGDATABASE         same as the dbname connection parameter\n"));
+	printf(_("  PGHOST             same as the host connection parameter\n"));
+	printf(_("  PGPORT             same as the port connection parameter\n"));
+	printf(_("  PGUSER             same as the user connection parameter\n"));
+	printf(_("  PGPASSWORD         possibility to set password (not recommended)\n"));
+	printf(_("  PGPASSFILE         password file (default ~/.pgpass)\n"));
+	printf(_("  PSQL_EDITOR, EDITOR, VISUAL\n"
+					 "                     editor used by \\e \\ef commands\n"));
+	printf(_("  PSQL_EDITOR_LINE_NUMBER_ARG\n"
+					 "                     style how line number is used in editor\n"));
+	printf(_("  PSQL_HISTORY       alternative location for the command history file\n"));
+	printf(_("  PSQLRC             alternative location of the user's .psqlrc file\n"));
+	printf(_("  SHELL              command executed by the \\! command\n"));
+	printf(_("  TMPDIR             directory for storing temporary files\n"));
+
+	printf(_("\nFor more information consult the psql section in the PostgreSQL\n"
+			 "documentation.\n\n"));
+	printf(_("Report bugs to <pgsql-bugs@postgresql.org>.\n"));
+}
+
 
 /*
  * helpSQL -- help with SQL commands
diff --git a/src/bin/psql/help.h b/src/bin/psql/help.h
index 054d5a4..e7affff 100644
--- a/src/bin/psql/help.h
+++ b/src/bin/psql/help.h
@@ -12,6 +12,8 @@ void		usage(void);
 
 void		slashUsage(unsigned short int pager);
 
+void		help_variables(void);
+
 void		helpSQL(const char *topic, unsigned short int pager);
 
 void		print_copyright(void);
diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c
index 45653a1..d911159 100644
--- a/src/bin/psql/startup.c
+++ b/src/bin/psql/startup.c
@@ -383,6 +383,7 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
 		{"expanded", no_argument, NULL, 'x'},
 		{"no-psqlrc", no_argument, NULL, 'X'},
 		{"help", no_argument, NULL, '?'},
+		{"help-variables", no_argument, NULL, 1},
 		{NULL, 0, NULL, 0}
 	};
 
@@ -566,6 +567,9 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
 					exit(EXIT_FAILURE);
 				}
 				break;
+			case 1:
+				help_variables();
+				exit(EXIT_SUCCESS);
 			default:
 				fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
 						pset.progname);
#11MauMau
maumau307@gmail.com
In reply to: Pavel Stehule (#10)

Hello,

From: "Pavel Stehule" <pavel.stehule@gmail.com>

fixed

Thank you. All is fine.

should be ""Environment variables". And this section lacks description
for Windows, such as:

+ printf(_(" NAME=VALUE [NAME=VALUE] psql ...\n or \\setenv NAME
[VALUE]
in interactive mode\n\n"));

+ printf(_(" PGPASSFILE password file (default ~/.pgpass)\n"));

??? -

I meant that how to set environment variables on Windows command prompt is
different from on UNIX/Linux, and the default password file path is also
different on Windows. Do we describe them in this help?

Lastly, to follow most of your descriptions, "s" at the end of the first
verb in these messages should be removed. For example, use "set" instead of
"sets".

+ printf(_("  COMP_KEYWORD_CASE  determines which letter case to use when 
completing an SQL key word\n"));
+ printf(_("  columns            sets the target width for the wrapped 
format\n"));
+ printf(_("  linestyle          sets the border line drawing style [ascii, 
old-ascii, unicode]\n"));
+ printf(_("  recordsep          specifies the record (line) separator to 
use in unaligned output format\n"));
+ printf(_("  title              sets the table title for any subsequently 
printed tables\n"));

This is all I noticed in the review.

Regards
MauMau

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#12Pavel Stehule
pavel.stehule@gmail.com
In reply to: MauMau (#11)

2014-06-26 15:26 GMT+02:00 MauMau <maumau307@gmail.com>:

Hello,

From: "Pavel Stehule" <pavel.stehule@gmail.com>

fixed

Thank you. All is fine.

should be ""Environment variables". And this section lacks description

for Windows, such as:

+ printf(_(" NAME=VALUE [NAME=VALUE] psql ...\n or \\setenv NAME
[VALUE]
in interactive mode\n\n"));

+ printf(_(" PGPASSFILE password file (default ~/.pgpass)\n"));

??? -

I meant that how to set environment variables on Windows command prompt is
different from on UNIX/Linux, and the default password file path is also
different on Windows. Do we describe them in this help?

hmm, I'll check it

Pavel

Show quoted text

Lastly, to follow most of your descriptions, "s" at the end of the first
verb in these messages should be removed. For example, use "set" instead
of "sets".

+ printf(_("  COMP_KEYWORD_CASE  determines which letter case to use when
completing an SQL key word\n"));
+ printf(_("  columns            sets the target width for the wrapped
format\n"));
+ printf(_("  linestyle          sets the border line drawing style
[ascii, old-ascii, unicode]\n"));
+ printf(_("  recordsep          specifies the record (line) separator to
use in unaligned output format\n"));
+ printf(_("  title              sets the table title for any subsequently
printed tables\n"));

This is all I noticed in the review.

Regards
MauMau

#13Petr Jelinek
petr@2ndquadrant.com
In reply to: Pavel Stehule (#12)
1 attachment(s)

Hello,

I went through the patch, seems mostly fine, I adjusted some wording,
removed the default .pgpass file info since it's not accurate, and
replaced couple of phrases with (hopefully) more informative ones.

--
Petr Jelinek http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

Attachments:

help-variables-06.patchtext/x-diff; name=help-variables-06.patchDownload
commit 4d77ccf19ac77dc0f43a58f4d2b74d4aebed871d
Author: Pavel Stehule <pavel.stehule@gooddata.com>
Date:   Mon Jun 23 19:38:41 2014 +0200

    without comments

diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index ee6ec3a..6a172dc 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -556,6 +556,15 @@ EOF
       </listitem>
     </varlistentry>
 
+    <varlistentry>
+      <term><option>--help-variables</></term>
+      <listitem>
+      <para>
+      Show help about <application>psql</application> variables,
+      and exit.
+      </para>
+      </listitem>
+    </varlistentry>
   </variablelist>
  </refsect1>
 
diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c
index 3aa3c16..1304e1a 100644
--- a/src/bin/psql/help.c
+++ b/src/bin/psql/help.c
@@ -78,12 +78,13 @@ usage(void)
 	printf(_("  -f, --file=FILENAME      execute commands from file, then exit\n"));
 	printf(_("  -l, --list               list available databases, then exit\n"));
 	printf(_("  -v, --set=, --variable=NAME=VALUE\n"
-			 "                           set psql variable NAME to VALUE\n"));
+			 "                           set psql variable NAME to VALUE e.g.: -v ON_ERROR_STOP=1\n"));
 	printf(_("  -V, --version            output version information, then exit\n"));
 	printf(_("  -X, --no-psqlrc          do not read startup file (~/.psqlrc)\n"));
 	printf(_("  -1 (\"one\"), --single-transaction\n"
 			 "                           execute as a single transaction (if non-interactive)\n"));
 	printf(_("  -?, --help               show this help, then exit\n"));
+	printf(_("  --help-variables         show a list of all specially treated variables, then exit\n"));
 
 	printf(_("\nInput and output options:\n"));
 	printf(_("  -a, --echo-all           echo all input from script\n"));
@@ -279,6 +280,92 @@ slashUsage(unsigned short int pager)
 }
 
 
+/*
+ * show list of available variables (options) from command line
+ */
+void
+help_variables(void)
+{
+	printf(_("List of specially treated variables.\n"));
+
+	printf(_("psql variables:\n"));
+	printf(_("Usage:\n"));
+	printf(_("  psql --set=NAME=VALUE\n  or \\set NAME VALUE in interactive mode\n\n"));
+
+	printf(_("  AUTOCOMMIT         successful SQL commands are automatically committed\n"));
+	printf(_("  COMP_KEYWORD_CASE  determines which letter case to use when completing an SQL key word\n"));
+	printf(_("  DBNAME             name of currently connected database\n"));
+	printf(_("  ECHO               control what input can be written to standard output [all, queries]\n"));
+	printf(_("  ECHO_HIDDEN        display internal queries executed by backslash commands\n"));
+	printf(_("  ENCODING           current client character set encoding\n"));
+	printf(_("  FETCH_COUNT        the number of result rows to fetch and display at a time\n"
+					 "                     (default: 0=unlimited)\n"));
+	printf(_("  HISTCONTROL        control history list [ignorespace, ignoredups, ignoreboth]\n"));
+	printf(_("  HISTFILE           file name used to store the history list\n"));
+	printf(_("  HISTSIZE           the number of commands to store in the command history\n"));
+	printf(_("  HOST               the currently connected database server\n"));
+	printf(_("  IGNOREEOF          if unset, sending an EOF to interactive session terminates application\n"));
+	printf(_("  LASTOID            the value of last affected OID\n"));
+	printf(_("  ON_ERROR_ROLLBACK  when on, the error doesn't stop transaction (uses implicit SAVEPOINTs)\n"));
+	printf(_("  ON_ERROR_STOP      stop batch execution after error\n"));
+	printf(_("  PORT               server port of the current connection\n"));
+	printf(_("  PROMPT1, PROMPT2, PROMPT3\n"
+					 "                     specify the psql prompt\n"));
+	printf(_("  QUIET              run quietly (same as -q option)\n"));
+	printf(_("  SINGLELINE         end of line terminates SQL command mode (same as -S option)\n"));
+	printf(_("  SINGLESTEP         single-step mode (same as -s option)\n"));
+	printf(_("  USER               the database user currently connected as\n"));
+	printf(_("  VERBOSITY          control verbosity of error reports [default, verbose, terse]\n"));
+
+	printf(_("\nPrinting options:\n"));
+	printf(_("Usage:\n"));
+	printf(_("  psql --pset=NAME[=VALUE]\n  or \\pset NAME [VALUE] in interactive mode\n\n"));
+
+	printf(_("  border             border style (number)\n"));
+	printf(_("  columns            set the target width for the wrapped format\n"));
+	printf(_("  expanded (or x)    toggle expanded output\n"));
+	printf(_("  fieldsep           field separator for unaligned output (default '|')\n"));
+	printf(_("  fieldsep_zero      set field separator in unaligned mode to zero\n"));
+	printf(_("  format             set output format [unaligned, aligned, wrapped, html, latex, ..]\n"));
+	printf(_("  footer             enable or disable display of the table foote [on, off]\n"));
+	printf(_("  linestyle          set the border line drawing style [ascii, old-ascii, unicode]\n"));
+	printf(_("  null               set the string to be printed in place of a null value\n"));
+	printf(_("  numericlocale      enable or disable display of a locale-specific character to separate\n"
+					 "                     groups digits [on, off]\n"));
+	printf(_("  pager              control the use of pager program of query and help output\n"));
+	printf(_("  recordsep          specify the record (line) separator to use in unaligned output format\n"));
+	printf(_("  recordsep_zero     set the record separator to use in unaligned output format to a zero byte.\n"));
+	printf(_("  tableattr (or T)   specify attributies for table tag in html format or proportional\n"
+					 "                     column width of left aligned data type in latex format\n"));
+	printf(_("  title              set the table title for any subsequently printed tables\n"));
+	printf(_("  tuples_only        when on, only actual table data is shown\n"));
+
+	printf(_("\nEnvironment variables:\n"));
+	printf(_("Usage:\n"));
+	printf(_("  NAME=VALUE [NAME=VALUE] psql ...\n  or \\setenv NAME [VALUE] in interactive mode\n\n"));
+
+	printf(_("  COLUMNS            number of columns for wrapped format\n"));
+	printf(_("  PAGER              used pager\n"));
+	printf(_("  PGDATABASE         same as the dbname connection parameter\n"));
+	printf(_("  PGHOST             same as the host connection parameter\n"));
+	printf(_("  PGPORT             same as the port connection parameter\n"));
+	printf(_("  PGUSER             same as the user connection parameter\n"));
+	printf(_("  PGPASSWORD         connection password (not recommended)\n"));
+	printf(_("  PGPASSFILE         password file name\n"));
+	printf(_("  PSQL_EDITOR, EDITOR, VISUAL\n"
+					 "                     editor used by \\e \\ef commands\n"));
+	printf(_("  PSQL_EDITOR_LINE_NUMBER_ARG\n"
+					 "                     style how line number is used in editor\n"));
+	printf(_("  PSQL_HISTORY       alternative location for the command history file\n"));
+	printf(_("  PSQLRC             alternative location of the user's .psqlrc file\n"));
+	printf(_("  SHELL              command executed by the \\! command\n"));
+	printf(_("  TMPDIR             directory for storing temporary files\n"));
+
+	printf(_("\nFor more information consult the psql section in the PostgreSQL\n"
+			 "documentation.\n\n"));
+	printf(_("Report bugs to <pgsql-bugs@postgresql.org>.\n"));
+}
+
 
 /*
  * helpSQL -- help with SQL commands
diff --git a/src/bin/psql/help.h b/src/bin/psql/help.h
index 054d5a4..e7affff 100644
--- a/src/bin/psql/help.h
+++ b/src/bin/psql/help.h
@@ -12,6 +12,8 @@ void		usage(void);
 
 void		slashUsage(unsigned short int pager);
 
+void		help_variables(void);
+
 void		helpSQL(const char *topic, unsigned short int pager);
 
 void		print_copyright(void);
diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c
index 45653a1..d911159 100644
--- a/src/bin/psql/startup.c
+++ b/src/bin/psql/startup.c
@@ -383,6 +383,7 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
 		{"expanded", no_argument, NULL, 'x'},
 		{"no-psqlrc", no_argument, NULL, 'X'},
 		{"help", no_argument, NULL, '?'},
+		{"help-variables", no_argument, NULL, 1},
 		{NULL, 0, NULL, 0}
 	};
 
@@ -566,6 +567,9 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
 					exit(EXIT_FAILURE);
 				}
 				break;
+			case 1:
+				help_variables();
+				exit(EXIT_SUCCESS);
 			default:
 				fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
 						pset.progname);
#14Pavel Stehule
pavel.stehule@gmail.com
In reply to: Petr Jelinek (#13)

Hello

thank you Peter, so now only setting for MS Windows is missing?

Regards

Pavel

2014-06-26 21:57 GMT+02:00 Petr Jelinek <petr@2ndquadrant.com>:

Show quoted text

Hello,

I went through the patch, seems mostly fine, I adjusted some wording,
removed the default .pgpass file info since it's not accurate, and replaced
couple of phrases with (hopefully) more informative ones.

--
Petr Jelinek http://www.2ndQuadrant.com/

PostgreSQL Development, 24x7 Support, Training & Services

#15Pavel Stehule
pavel.stehule@gmail.com
In reply to: Pavel Stehule (#14)
1 attachment(s)

Hello

I modified description of setting system variables in dependency on O.S.

Regards

Pavel

2014-06-27 8:54 GMT+02:00 Pavel Stehule <pavel.stehule@gmail.com>:

Show quoted text

Hello

thank you Peter, so now only setting for MS Windows is missing?

Regards

Pavel

2014-06-26 21:57 GMT+02:00 Petr Jelinek <petr@2ndquadrant.com>:

Hello,

I went through the patch, seems mostly fine, I adjusted some wording,
removed the default .pgpass file info since it's not accurate, and replaced
couple of phrases with (hopefully) more informative ones.

--
Petr Jelinek http://www.2ndQuadrant.com/

PostgreSQL Development, 24x7 Support, Training & Services

Attachments:

help-variables-07.patchtext/x-patch; charset=US-ASCII; name=help-variables-07.patchDownload
commit 44ba9d7fc1816dde4605ef59ea68b92b8ceb1c57
Author: Pavel Stehule <pavel.stehule@gooddata.com>
Date:   Sat Jun 28 14:19:47 2014 +0200

    initial

diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index ee6ec3a..6a172dc 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -556,6 +556,15 @@ EOF
       </listitem>
     </varlistentry>
 
+    <varlistentry>
+      <term><option>--help-variables</></term>
+      <listitem>
+      <para>
+      Show help about <application>psql</application> variables,
+      and exit.
+      </para>
+      </listitem>
+    </varlistentry>
   </variablelist>
  </refsect1>
 
diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c
index 3aa3c16..d7da7c3 100644
--- a/src/bin/psql/help.c
+++ b/src/bin/psql/help.c
@@ -78,12 +78,13 @@ usage(void)
 	printf(_("  -f, --file=FILENAME      execute commands from file, then exit\n"));
 	printf(_("  -l, --list               list available databases, then exit\n"));
 	printf(_("  -v, --set=, --variable=NAME=VALUE\n"
-			 "                           set psql variable NAME to VALUE\n"));
+			 "                           set psql variable NAME to VALUE e.g.: -v ON_ERROR_STOP=1\n"));
 	printf(_("  -V, --version            output version information, then exit\n"));
 	printf(_("  -X, --no-psqlrc          do not read startup file (~/.psqlrc)\n"));
 	printf(_("  -1 (\"one\"), --single-transaction\n"
 			 "                           execute as a single transaction (if non-interactive)\n"));
 	printf(_("  -?, --help               show this help, then exit\n"));
+	printf(_("  --help-variables         show a list of all specially treated variables, then exit\n"));
 
 	printf(_("\nInput and output options:\n"));
 	printf(_("  -a, --echo-all           echo all input from script\n"));
@@ -279,6 +280,98 @@ slashUsage(unsigned short int pager)
 }
 
 
+/*
+ * show list of available variables (options) from command line
+ */
+void
+help_variables(void)
+{
+	printf(_("List of specially treated variables.\n"));
+
+	printf(_("psql variables:\n"));
+	printf(_("Usage:\n"));
+	printf(_("  psql --set=NAME=VALUE\n  or \\set NAME VALUE in interactive mode\n\n"));
+
+	printf(_("  AUTOCOMMIT         successful SQL commands are automatically committed\n"));
+	printf(_("  COMP_KEYWORD_CASE  determines which letter case to use when completing an SQL key word\n"));
+	printf(_("  DBNAME             name of currently connected database\n"));
+	printf(_("  ECHO               control what input can be written to standard output [all, queries]\n"));
+	printf(_("  ECHO_HIDDEN        display internal queries executed by backslash commands\n"));
+	printf(_("  ENCODING           current client character set encoding\n"));
+	printf(_("  FETCH_COUNT        the number of result rows to fetch and display at a time\n"
+					 "                     (default: 0=unlimited)\n"));
+	printf(_("  HISTCONTROL        control history list [ignorespace, ignoredups, ignoreboth]\n"));
+	printf(_("  HISTFILE           file name used to store the history list\n"));
+	printf(_("  HISTSIZE           the number of commands to store in the command history\n"));
+	printf(_("  HOST               the currently connected database server\n"));
+	printf(_("  IGNOREEOF          if unset, sending an EOF to interactive session terminates application\n"));
+	printf(_("  LASTOID            the value of last affected OID\n"));
+	printf(_("  ON_ERROR_ROLLBACK  when on, the error doesn't stop transaction (uses implicit SAVEPOINTs)\n"));
+	printf(_("  ON_ERROR_STOP      stop batch execution after error\n"));
+	printf(_("  PORT               server port of the current connection\n"));
+	printf(_("  PROMPT1, PROMPT2, PROMPT3\n"
+					 "                     specify the psql prompt\n"));
+	printf(_("  QUIET              run quietly (same as -q option)\n"));
+	printf(_("  SINGLELINE         end of line terminates SQL command mode (same as -S option)\n"));
+	printf(_("  SINGLESTEP         single-step mode (same as -s option)\n"));
+	printf(_("  USER               the database user currently connected as\n"));
+	printf(_("  VERBOSITY          control verbosity of error reports [default, verbose, terse]\n"));
+
+	printf(_("\nPrinting options:\n"));
+	printf(_("Usage:\n"));
+	printf(_("  psql --pset=NAME[=VALUE]\n  or \\pset NAME [VALUE] in interactive mode\n\n"));
+
+	printf(_("  border             border style (number)\n"));
+	printf(_("  columns            set the target width for the wrapped format\n"));
+	printf(_("  expanded (or x)    toggle expanded output\n"));
+	printf(_("  fieldsep           field separator for unaligned output (default '|')\n"));
+	printf(_("  fieldsep_zero      set field separator in unaligned mode to zero\n"));
+	printf(_("  format             set output format [unaligned, aligned, wrapped, html, latex, ..]\n"));
+	printf(_("  footer             enable or disable display of the table foote [on, off]\n"));
+	printf(_("  linestyle          set the border line drawing style [ascii, old-ascii, unicode]\n"));
+	printf(_("  null               set the string to be printed in place of a null value\n"));
+	printf(_("  numericlocale      enable or disable display of a locale-specific character to separate\n"
+					 "                     groups digits [on, off]\n"));
+	printf(_("  pager              control the use of pager program of query and help output\n"));
+	printf(_("  recordsep          specify the record (line) separator to use in unaligned output format\n"));
+	printf(_("  recordsep_zero     set the record separator to use in unaligned output format to a zero byte.\n"));
+	printf(_("  tableattr (or T)   specify attributies for table tag in html format or proportional\n"
+					 "                     column width of left aligned data type in latex format\n"));
+	printf(_("  title              set the table title for any subsequently printed tables\n"));
+	printf(_("  tuples_only        when on, only actual table data is shown\n"));
+
+	printf(_("\nEnvironment variables:\n"));
+	printf(_("Usage:\n"));
+
+#ifndef WIN32
+	printf(_("  NAME=VALUE [NAME=VALUE] psql ...\n  or \\setenv NAME [VALUE] in interactive mode\n\n"));
+#else
+	printf(_("  set NAME=VALUE\n  psql ...\n  or \\setenv NAME VALUE in interactive mode\n\n"));
+#endif
+
+	printf(_("  COLUMNS            number of columns for wrapped format\n"));
+	printf(_("  PAGER              used pager\n"));
+	printf(_("  PGAPPNAME          same as the application_name connection parameter\n"));
+	printf(_("  PGDATABASE         same as the dbname connection parameter\n"));
+	printf(_("  PGHOST             same as the host connection parameter\n"));
+	printf(_("  PGPORT             same as the port connection parameter\n"));
+	printf(_("  PGUSER             same as the user connection parameter\n"));
+	printf(_("  PGPASSWORD         connection password (not recommended)\n"));
+	printf(_("  PGPASSFILE         password file name\n"));
+	printf(_("  PSQL_EDITOR, EDITOR, VISUAL\n"
+					 "                     editor used by \\e \\ef commands\n"));
+	printf(_("  PSQL_EDITOR_LINE_NUMBER_ARG\n"
+					 "                     style how line number is used in editor\n"));
+	printf(_("  PSQL_HISTORY       alternative location for the command history file\n"));
+	printf(_("  PSQLRC             alternative location of the user's .psqlrc file\n"));
+	printf(_("  SHELL              command executed by the \\! command\n"));
+	printf(_("  TMPDIR             directory for storing temporary files\n"));
+
+	printf(_("\nFor more information consult the psql section in the PostgreSQL\n"
+			 "documentation.\n\n"));
+	printf(_("Report bugs to <pgsql-bugs@postgresql.org>.\n"));
+}
+
 
 /*
  * helpSQL -- help with SQL commands
diff --git a/src/bin/psql/help.h b/src/bin/psql/help.h
index 054d5a4..e7affff 100644
--- a/src/bin/psql/help.h
+++ b/src/bin/psql/help.h
@@ -12,6 +12,8 @@ void		usage(void);
 
 void		slashUsage(unsigned short int pager);
 
+void		help_variables(void);
+
 void		helpSQL(const char *topic, unsigned short int pager);
 
 void		print_copyright(void);
diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c
index 45653a1..d911159 100644
--- a/src/bin/psql/startup.c
+++ b/src/bin/psql/startup.c
@@ -383,6 +383,7 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
 		{"expanded", no_argument, NULL, 'x'},
 		{"no-psqlrc", no_argument, NULL, 'X'},
 		{"help", no_argument, NULL, '?'},
+		{"help-variables", no_argument, NULL, 1},
 		{NULL, 0, NULL, 0}
 	};
 
@@ -566,6 +567,9 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
 					exit(EXIT_FAILURE);
 				}
 				break;
+			case 1:
+				help_variables();
+				exit(EXIT_SUCCESS);
 			default:
 				fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
 						pset.progname);
#16MauMau
maumau307@gmail.com
In reply to: Pavel Stehule (#15)

From: "Pavel Stehule" <pavel.stehule@gmail.com>

I modified description of setting system variables in dependency on O.S.

Thank you, it's almost OK. As mentioned in my previous mail, I think
"determines" should be "determine" to follow other messages. I'll mark this
patch as ready for committer when this is fixed.

+ printf(_(" COMP_KEYWORD_CASE determines which letter case to use when
completing an SQL key word\n"));

Personally, I don't think we have to describe how to set environment
variables, because it's preliminary knowledge and not specific to
PostgreSQL. However, I don't mind if you retain or remove the description.

Regards
MauMau

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#17Pavel Stehule
pavel.stehule@gmail.com
In reply to: MauMau (#16)
1 attachment(s)

Hi

2014-06-29 0:48 GMT+02:00 MauMau <maumau307@gmail.com>:

From: "Pavel Stehule" <pavel.stehule@gmail.com>

I modified description of setting system variables in dependency on O.S.

Thank you, it's almost OK. As mentioned in my previous mail, I think
"determines" should be "determine" to follow other messages. I'll mark
this patch as ready for committer when this is fixed.

fixes

+ printf(_(" COMP_KEYWORD_CASE determines which letter case to use when
completing an SQL key word\n"));

Personally, I don't think we have to describe how to set environment
variables, because it's preliminary knowledge and not specific to
PostgreSQL. However, I don't mind if you retain or remove the description.

ok

Regards

Pavel

Show quoted text

Regards
MauMau

Attachments:

help-variables-08.patchtext/x-patch; charset=US-ASCII; name=help-variables-08.patchDownload
commit 44ba9d7fc1816dde4605ef59ea68b92b8ceb1c57
Author: Pavel Stehule <pavel.stehule@gooddata.com>
Date:   Sat Jun 28 14:19:47 2014 +0200

    initial

diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index ee6ec3a..6a172dc 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -556,6 +556,15 @@ EOF
       </listitem>
     </varlistentry>
 
+    <varlistentry>
+      <term><option>--help-variables</></term>
+      <listitem>
+      <para>
+      Show help about <application>psql</application> variables,
+      and exit.
+      </para>
+      </listitem>
+    </varlistentry>
   </variablelist>
  </refsect1>
 
diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c
index 3aa3c16..d7da7c3 100644
--- a/src/bin/psql/help.c
+++ b/src/bin/psql/help.c
@@ -78,12 +78,13 @@ usage(void)
 	printf(_("  -f, --file=FILENAME      execute commands from file, then exit\n"));
 	printf(_("  -l, --list               list available databases, then exit\n"));
 	printf(_("  -v, --set=, --variable=NAME=VALUE\n"
-			 "                           set psql variable NAME to VALUE\n"));
+			 "                           set psql variable NAME to VALUE e.g.: -v ON_ERROR_STOP=1\n"));
 	printf(_("  -V, --version            output version information, then exit\n"));
 	printf(_("  -X, --no-psqlrc          do not read startup file (~/.psqlrc)\n"));
 	printf(_("  -1 (\"one\"), --single-transaction\n"
 			 "                           execute as a single transaction (if non-interactive)\n"));
 	printf(_("  -?, --help               show this help, then exit\n"));
+	printf(_("  --help-variables         show a list of all specially treated variables, then exit\n"));
 
 	printf(_("\nInput and output options:\n"));
 	printf(_("  -a, --echo-all           echo all input from script\n"));
@@ -279,6 +280,98 @@ slashUsage(unsigned short int pager)
 }
 
 
+/*
+ * show list of available variables (options) from command line
+ */
+void
+help_variables(void)
+{
+	printf(_("List of specially treated variables.\n"));
+
+	printf(_("psql variables:\n"));
+	printf(_("Usage:\n"));
+	printf(_("  psql --set=NAME=VALUE\n  or \\set NAME VALUE in interactive mode\n\n"));
+
+	printf(_("  AUTOCOMMIT         successful SQL commands are automatically committed\n"));
+	printf(_("  COMP_KEYWORD_CASE  determine which letter case to use when completing an SQL key word\n"));
+	printf(_("  DBNAME             name of currently connected database\n"));
+	printf(_("  ECHO               control what input can be written to standard output [all, queries]\n"));
+	printf(_("  ECHO_HIDDEN        display internal queries executed by backslash commands\n"));
+	printf(_("  ENCODING           current client character set encoding\n"));
+	printf(_("  FETCH_COUNT        the number of result rows to fetch and display at a time\n"
+					 "                     (default: 0=unlimited)\n"));
+	printf(_("  HISTCONTROL        control history list [ignorespace, ignoredups, ignoreboth]\n"));
+	printf(_("  HISTFILE           file name used to store the history list\n"));
+	printf(_("  HISTSIZE           the number of commands to store in the command history\n"));
+	printf(_("  HOST               the currently connected database server\n"));
+	printf(_("  IGNOREEOF          if unset, sending an EOF to interactive session terminates application\n"));
+	printf(_("  LASTOID            the value of last affected OID\n"));
+	printf(_("  ON_ERROR_ROLLBACK  when on, the error doesn't stop transaction (uses implicit SAVEPOINTs)\n"));
+	printf(_("  ON_ERROR_STOP      stop batch execution after error\n"));
+	printf(_("  PORT               server port of the current connection\n"));
+	printf(_("  PROMPT1, PROMPT2, PROMPT3\n"
+					 "                     specify the psql prompt\n"));
+	printf(_("  QUIET              run quietly (same as -q option)\n"));
+	printf(_("  SINGLELINE         end of line terminates SQL command mode (same as -S option)\n"));
+	printf(_("  SINGLESTEP         single-step mode (same as -s option)\n"));
+	printf(_("  USER               the database user currently connected as\n"));
+	printf(_("  VERBOSITY          control verbosity of error reports [default, verbose, terse]\n"));
+
+	printf(_("\nPrinting options:\n"));
+	printf(_("Usage:\n"));
+	printf(_("  psql --pset=NAME[=VALUE]\n  or \\pset NAME [VALUE] in interactive mode\n\n"));
+
+	printf(_("  border             border style (number)\n"));
+	printf(_("  columns            set the target width for the wrapped format\n"));
+	printf(_("  expanded (or x)    toggle expanded output\n"));
+	printf(_("  fieldsep           field separator for unaligned output (default '|')\n"));
+	printf(_("  fieldsep_zero      set field separator in unaligned mode to zero\n"));
+	printf(_("  format             set output format [unaligned, aligned, wrapped, html, latex, ..]\n"));
+	printf(_("  footer             enable or disable display of the table foote [on, off]\n"));
+	printf(_("  linestyle          set the border line drawing style [ascii, old-ascii, unicode]\n"));
+	printf(_("  null               set the string to be printed in place of a null value\n"));
+	printf(_("  numericlocale      enable or disable display of a locale-specific character to separate\n"
+					 "                     groups digits [on, off]\n"));
+	printf(_("  pager              control the use of pager program of query and help output\n"));
+	printf(_("  recordsep          specify the record (line) separator to use in unaligned output format\n"));
+	printf(_("  recordsep_zero     set the record separator to use in unaligned output format to a zero byte.\n"));
+	printf(_("  tableattr (or T)   specify attributies for table tag in html format or proportional\n"
+					 "                     column width of left aligned data type in latex format\n"));
+	printf(_("  title              set the table title for any subsequently printed tables\n"));
+	printf(_("  tuples_only        when on, only actual table data is shown\n"));
+
+	printf(_("\nEnvironment variables:\n"));
+	printf(_("Usage:\n"));
+
+#ifndef WIN32
+	printf(_("  NAME=VALUE [NAME=VALUE] psql ...\n  or \\setenv NAME [VALUE] in interactive mode\n\n"));
+#else
+	printf(_("  set NAME=VALUE\n  psql ...\n  or \\setenv NAME VALUE in interactive mode\n\n"));
+#endif
+
+	printf(_("  COLUMNS            number of columns for wrapped format\n"));
+	printf(_("  PAGER              used pager\n"));
+	printf(_("  PGAPPNAME          same as the application_name connection parameter\n"));
+	printf(_("  PGDATABASE         same as the dbname connection parameter\n"));
+	printf(_("  PGHOST             same as the host connection parameter\n"));
+	printf(_("  PGPORT             same as the port connection parameter\n"));
+	printf(_("  PGUSER             same as the user connection parameter\n"));
+	printf(_("  PGPASSWORD         connection password (not recommended)\n"));
+	printf(_("  PGPASSFILE         password file name\n"));
+	printf(_("  PSQL_EDITOR, EDITOR, VISUAL\n"
+					 "                     editor used by \\e \\ef commands\n"));
+	printf(_("  PSQL_EDITOR_LINE_NUMBER_ARG\n"
+					 "                     style how line number is used in editor\n"));
+	printf(_("  PSQL_HISTORY       alternative location for the command history file\n"));
+	printf(_("  PSQLRC             alternative location of the user's .psqlrc file\n"));
+	printf(_("  SHELL              command executed by the \\! command\n"));
+	printf(_("  TMPDIR             directory for storing temporary files\n"));
+
+	printf(_("\nFor more information consult the psql section in the PostgreSQL\n"
+			 "documentation.\n\n"));
+	printf(_("Report bugs to <pgsql-bugs@postgresql.org>.\n"));
+}
+
 
 /*
  * helpSQL -- help with SQL commands
diff --git a/src/bin/psql/help.h b/src/bin/psql/help.h
index 054d5a4..e7affff 100644
--- a/src/bin/psql/help.h
+++ b/src/bin/psql/help.h
@@ -12,6 +12,8 @@ void		usage(void);
 
 void		slashUsage(unsigned short int pager);
 
+void		help_variables(void);
+
 void		helpSQL(const char *topic, unsigned short int pager);
 
 void		print_copyright(void);
diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c
index 45653a1..d911159 100644
--- a/src/bin/psql/startup.c
+++ b/src/bin/psql/startup.c
@@ -383,6 +383,7 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
 		{"expanded", no_argument, NULL, 'x'},
 		{"no-psqlrc", no_argument, NULL, 'X'},
 		{"help", no_argument, NULL, '?'},
+		{"help-variables", no_argument, NULL, 1},
 		{NULL, 0, NULL, 0}
 	};
 
@@ -566,6 +567,9 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
 					exit(EXIT_FAILURE);
 				}
 				break;
+			case 1:
+				help_variables();
+				exit(EXIT_SUCCESS);
 			default:
 				fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
 						pset.progname);
#18MauMau
maumau307@gmail.com
In reply to: Pavel Stehule (#17)

Thanks, I marked it as ready for committer. I hope Fujii san or another
committer will commit this, refining English expression if necessary.

Regards
MauMau

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#19Pavel Stehule
pavel.stehule@gmail.com
In reply to: MauMau (#18)

2014-06-29 13:35 GMT+02:00 MauMau <maumau307@gmail.com>:

Thanks, I marked it as ready for committer. I hope Fujii san or another
committer will commit this, refining English expression if necessary.

sure

Thank you very much

Regards

Pavel

Show quoted text

Regards
MauMau

#20Abhijit Menon-Sen
ams@2ndQuadrant.com
In reply to: MauMau (#18)
1 attachment(s)

At 2014-06-29 20:35:04 +0900, maumau307@gmail.com wrote:

Thanks, I marked it as ready for committer. I hope Fujii san or
another committer will commit this, refining English expression if
necessary.

Since it was just a matter of editing, I went through the patch and
corrected various minor errors (typos, awkwardness, etc.). I agree
that this is now ready for committer.

I've attached the updated diff.

-- Abhijit

Attachments:

help-variables-09.patchtext/x-diff; charset=us-asciiDownload
diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index ee6ec3a..6a172dc 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -556,6 +556,15 @@ EOF
       </listitem>
     </varlistentry>
 
+    <varlistentry>
+      <term><option>--help-variables</></term>
+      <listitem>
+      <para>
+      Show help about <application>psql</application> variables,
+      and exit.
+      </para>
+      </listitem>
+    </varlistentry>
   </variablelist>
  </refsect1>
 
diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c
index 3aa3c16..9ff2dd9 100644
--- a/src/bin/psql/help.c
+++ b/src/bin/psql/help.c
@@ -78,12 +78,13 @@ usage(void)
 	printf(_("  -f, --file=FILENAME      execute commands from file, then exit\n"));
 	printf(_("  -l, --list               list available databases, then exit\n"));
 	printf(_("  -v, --set=, --variable=NAME=VALUE\n"
-			 "                           set psql variable NAME to VALUE\n"));
+			 "                           set psql variable NAME to VALUE e.g.: -v ON_ERROR_STOP=1\n"));
 	printf(_("  -V, --version            output version information, then exit\n"));
 	printf(_("  -X, --no-psqlrc          do not read startup file (~/.psqlrc)\n"));
 	printf(_("  -1 (\"one\"), --single-transaction\n"
 			 "                           execute as a single transaction (if non-interactive)\n"));
 	printf(_("  -?, --help               show this help, then exit\n"));
+	printf(_("  --help-variables         show a list of all specially treated variables, then exit\n"));
 
 	printf(_("\nInput and output options:\n"));
 	printf(_("  -a, --echo-all           echo all input from script\n"));
@@ -279,6 +280,99 @@ slashUsage(unsigned short int pager)
 }
 
 
+/*
+ * show list of available variables (options) from command line
+ */
+void
+help_variables(void)
+{
+	printf(_("List of specially treated variables.\n"));
+
+	printf(_("psql variables:\n"));
+	printf(_("Usage:\n"));
+	printf(_("  psql --set=NAME=VALUE\n  or \\set NAME VALUE in interactive mode\n\n"));
+
+	printf(_("  AUTOCOMMIT         if set, successful SQL commands are automatically committed\n"));
+	printf(_("  COMP_KEYWORD_CASE  determine the case used to complete SQL keywords\n"
+					 "                     [lower, upper, preserve-lower, preserve-upper]\n"));
+	printf(_("  DBNAME             the currently connected database name\n"));
+	printf(_("  ECHO               control what input is written to standard output [all, queries]\n"));
+	printf(_("  ECHO_HIDDEN        display internal queries executed by backslash commands\n"));
+	printf(_("  ENCODING           current client character set encoding\n"));
+	printf(_("  FETCH_COUNT        the number of result rows to fetch and display at a time\n"
+					 "                     (default: 0=unlimited)\n"));
+	printf(_("  HISTCONTROL        control history list [ignorespace, ignoredups, ignoreboth]\n"));
+	printf(_("  HISTFILE           file name used to store the history list\n"));
+	printf(_("  HISTSIZE           the number of commands to store in the command history\n"));
+	printf(_("  HOST               the currently connected database server\n"));
+	printf(_("  IGNOREEOF          if unset, sending an EOF to interactive session terminates application\n"));
+	printf(_("  LASTOID            the value of last affected OID\n"));
+	printf(_("  ON_ERROR_ROLLBACK  if set, an error doesn't stop a transaction (uses implicit SAVEPOINTs)\n"));
+	printf(_("  ON_ERROR_STOP      stop batch execution after error\n"));
+	printf(_("  PORT               server port of the current connection\n"));
+	printf(_("  PROMPT1, PROMPT2, PROMPT3\n"
+					 "                     specify the psql prompt\n"));
+	printf(_("  QUIET              run quietly (same as -q option)\n"));
+	printf(_("  SINGLELINE         end of line terminates SQL command mode (same as -S option)\n"));
+	printf(_("  SINGLESTEP         single-step mode (same as -s option)\n"));
+	printf(_("  USER               the currently connected database user\n"));
+	printf(_("  VERBOSITY          control verbosity of error reports [default, verbose, terse]\n"));
+
+	printf(_("\nPrinting options:\n"));
+	printf(_("Usage:\n"));
+	printf(_("  psql --pset=NAME[=VALUE]\n  or \\pset NAME [VALUE] in interactive mode\n\n"));
+
+	printf(_("  border             border style (number)\n"));
+	printf(_("  columns            set the target width for the wrapped format\n"));
+	printf(_("  expanded (or x)    toggle expanded output\n"));
+	printf(_("  fieldsep           field separator for unaligned output (default '|')\n"));
+	printf(_("  fieldsep_zero      set field separator in unaligned mode to zero\n"));
+	printf(_("  format             set output format [unaligned, aligned, wrapped, html, latex, ..]\n"));
+	printf(_("  footer             enable or disable display of the table footer [on, off]\n"));
+	printf(_("  linestyle          set the border line drawing style [ascii, old-ascii, unicode]\n"));
+	printf(_("  null               set the string to be printed in place of a null value\n"));
+	printf(_("  numericlocale      enable or disable display of a locale-specific character to separate\n"
+					 "                     groups of digits [on, off]\n"));
+	printf(_("  pager              control when an external pager is used [yes, no, always]\n"));
+	printf(_("  recordsep          specify the record (line) separator to use in unaligned output format\n"));
+	printf(_("  recordsep_zero     set the record separator to use in unaligned output format to a zero byte.\n"));
+	printf(_("  tableattr (or T)   specify attributes for table tag in html format or proportional\n"
+					 "                     column width of left aligned data type in latex format\n"));
+	printf(_("  title              set the table title for any subsequently printed tables\n"));
+	printf(_("  tuples_only        if set, only actual table data is shown\n"));
+
+	printf(_("\nEnvironment variables:\n"));
+	printf(_("Usage:\n"));
+
+#ifndef WIN32
+	printf(_("  NAME=VALUE [NAME=VALUE] psql ...\n  or \\setenv NAME [VALUE] in interactive mode\n\n"));
+#else
+	printf(_("  set NAME=VALUE\n  psql ...\n  or \\setenv NAME VALUE in interactive mode\n\n"));
+#endif
+
+	printf(_("  COLUMNS            number of columns for wrapped format\n"));
+	printf(_("  PAGER              name of external pager program\n"));
+	printf(_("  PGAPPNAME          same as the application_name connection parameter\n"));
+	printf(_("  PGDATABASE         same as the dbname connection parameter\n"));
+	printf(_("  PGHOST             same as the host connection parameter\n"));
+	printf(_("  PGPORT             same as the port connection parameter\n"));
+	printf(_("  PGUSER             same as the user connection parameter\n"));
+	printf(_("  PGPASSWORD         connection password (not recommended)\n"));
+	printf(_("  PGPASSFILE         password file name\n"));
+	printf(_("  PSQL_EDITOR, EDITOR, VISUAL\n"
+					 "                     editor used by the \\e and \\ef commands\n"));
+	printf(_("  PSQL_EDITOR_LINENUMBER_ARG\n"
+					 "                     how to specify a line number when invoking the editor\n"));
+	printf(_("  PSQL_HISTORY       alternative location for the command history file\n"));
+	printf(_("  PSQLRC             alternative location for the user's .psqlrc file\n"));
+	printf(_("  SHELL              shell used by the \\! command\n"));
+	printf(_("  TMPDIR             directory for temporary files\n"));
+
+	printf(_("\nFor more information consult the psql section in the PostgreSQL\n"
+			 "documentation.\n\n"));
+	printf(_("Report bugs to <pgsql-bugs@postgresql.org>.\n"));
+}
+
 
 /*
  * helpSQL -- help with SQL commands
diff --git a/src/bin/psql/help.h b/src/bin/psql/help.h
index 054d5a4..e7affff 100644
--- a/src/bin/psql/help.h
+++ b/src/bin/psql/help.h
@@ -12,6 +12,8 @@ void		usage(void);
 
 void		slashUsage(unsigned short int pager);
 
+void		help_variables(void);
+
 void		helpSQL(const char *topic, unsigned short int pager);
 
 void		print_copyright(void);
diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c
index 45653a1..d911159 100644
--- a/src/bin/psql/startup.c
+++ b/src/bin/psql/startup.c
@@ -383,6 +383,7 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
 		{"expanded", no_argument, NULL, 'x'},
 		{"no-psqlrc", no_argument, NULL, 'X'},
 		{"help", no_argument, NULL, '?'},
+		{"help-variables", no_argument, NULL, 1},
 		{NULL, 0, NULL, 0}
 	};
 
@@ -566,6 +567,9 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
 					exit(EXIT_FAILURE);
 				}
 				break;
+			case 1:
+				help_variables();
+				exit(EXIT_SUCCESS);
 			default:
 				fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
 						pset.progname);
#21Pavel Stehule
pavel.stehule@gmail.com
In reply to: Abhijit Menon-Sen (#20)

2014-06-29 15:24 GMT+02:00 Abhijit Menon-Sen <ams@2ndquadrant.com>:

At 2014-06-29 20:35:04 +0900, maumau307@gmail.com wrote:

Thanks, I marked it as ready for committer. I hope Fujii san or
another committer will commit this, refining English expression if
necessary.

Since it was just a matter of editing, I went through the patch and
corrected various minor errors (typos, awkwardness, etc.). I agree
that this is now ready for committer.

I've attached the updated diff.

I checked it, and it looks well

Thank you

Regards

Pavel

Show quoted text

-- Abhijit

#22Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Abhijit Menon-Sen (#20)

Abhijit Menon-Sen wrote:

At 2014-06-29 20:35:04 +0900, maumau307@gmail.com wrote:

Thanks, I marked it as ready for committer. I hope Fujii san or
another committer will commit this, refining English expression if
necessary.

Since it was just a matter of editing, I went through the patch and
corrected various minor errors (typos, awkwardness, etc.). I agree
that this is now ready for committer.

FWIW I think "determines" was correct.

--
�lvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#23Andres Freund
andres@2ndquadrant.com
In reply to: Abhijit Menon-Sen (#20)

On 2014-06-29 18:54:50 +0530, Abhijit Menon-Sen wrote:

At 2014-06-29 20:35:04 +0900, maumau307@gmail.com wrote:

Thanks, I marked it as ready for committer. I hope Fujii san or
another committer will commit this, refining English expression if
necessary.

Since it was just a matter of editing, I went through the patch and
corrected various minor errors (typos, awkwardness, etc.). I agree
that this is now ready for committer.

I've attached the updated diff.

I'm looking at committing this, but I wonder: Shouldn't this be
accessible from inside psql as well? I.e. as a backslash command?

Greetings,

Andres Freund

--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#24Petr Jelinek
petr@2ndquadrant.com
In reply to: Andres Freund (#23)

On 26/08/14 13:20, Andres Freund wrote:

I'm looking at committing this, but I wonder: Shouldn't this be
accessible from inside psql as well? I.e. as a backslash command?

+1

--
Petr Jelinek http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#25Pavel Stehule
pavel.stehule@gmail.com
In reply to: Petr Jelinek (#24)

2014-08-26 13:30 GMT+02:00 Petr Jelinek <petr@2ndquadrant.com>:

On 26/08/14 13:20, Andres Freund wrote:

I'm looking at committing this, but I wonder: Shouldn't this be
accessible from inside psql as well? I.e. as a backslash command?

+1

have you idea about command name? \?+

Pavel

Show quoted text

--
Petr Jelinek http://www.2ndQuadrant.com/

PostgreSQL Development, 24x7 Support, Training & Services

#26Andres Freund
andres@2ndquadrant.com
In reply to: Pavel Stehule (#25)

On 2014-08-26 13:44:16 +0200, Pavel Stehule wrote:

2014-08-26 13:30 GMT+02:00 Petr Jelinek <petr@2ndquadrant.com>:

On 26/08/14 13:20, Andres Freund wrote:

I'm looking at committing this, but I wonder: Shouldn't this be
accessible from inside psql as well? I.e. as a backslash command?

+1

have you idea about command name? \?+

Some ideas:

\hv
\help-variables
\? set
\? variables

Greetings,

Andres Freund

--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#27Pavel Stehule
pavel.stehule@gmail.com
In reply to: Andres Freund (#26)
1 attachment(s)

Hi

I chose \? xxx, because it is related to psql features. I wrote commands:

\? options
\? variables

comments?

Regards

Pavel

2014-08-26 13:48 GMT+02:00 Andres Freund <andres@2ndquadrant.com>:

Show quoted text

On 2014-08-26 13:44:16 +0200, Pavel Stehule wrote:

2014-08-26 13:30 GMT+02:00 Petr Jelinek <petr@2ndquadrant.com>:

On 26/08/14 13:20, Andres Freund wrote:

I'm looking at committing this, but I wonder: Shouldn't this be
accessible from inside psql as well? I.e. as a backslash command?

+1

have you idea about command name? \?+

Some ideas:

\hv
\help-variables
\? set
\? variables

Greetings,

Andres Freund

--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

Attachments:

help-variables-10.patchtext/x-patch; charset=US-ASCII; name=help-variables-10.patchDownload
commit 1c00470629f31d61886ff9ae95a6855693f358c8
Author: Pavel Stehule <pavel.stehule@gooddata.com>
Date:   Wed Aug 27 22:47:07 2014 +0200

    access to help_variables and usage from psql via psql command

diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index 74d4618..6d3189d 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -568,6 +568,15 @@ EOF
       </listitem>
     </varlistentry>
 
+    <varlistentry>
+      <term><option>--help-variables</></term>
+      <listitem>
+      <para>
+      Show help about <application>psql</application> variables,
+      and exit.
+      </para>
+      </listitem>
+    </varlistentry>
   </variablelist>
  </refsect1>
 
@@ -2572,10 +2581,12 @@ testdb=&gt; <userinput>\setenv LESS -imx4F</userinput>
 
 
       <varlistentry>
-        <term><literal>\?</literal></term>
+        <term><literal>\? [ options | variables ]</literal></term>
         <listitem>
         <para>
-        Shows help information about the backslash commands.
+        Shows help information about the backslash commands.  This command can have a
+        option "variables" or "options" to take help for psql configuration variables
+        or psql command line options.
         </para>
         </listitem>
       </varlistentry>
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index e27ff8c..12cbb20 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -1503,7 +1503,19 @@ exec_command(const char *cmd,
 
 	/* \? -- slash command help */
 	else if (strcmp(cmd, "?") == 0)
-		slashUsage(pset.popt.topt.pager);
+	{
+		char	   *opt0 = psql_scan_slash_option(scan_state,
+													OT_NORMAL, NULL, false);
+
+		if (!opt0)
+			slashUsage(pset.popt.topt.pager);
+		else if (strcmp(opt0, "variables") == 0)
+			help_variables(pset.popt.topt.pager);
+		else if (strcmp(opt0, "options") == 0)
+			usage(pset.popt.topt.pager);
+		else
+			slashUsage(pset.popt.topt.pager);
+	}
 
 #if 0
 
diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c
index f8f000f..5e7953d 100644
--- a/src/bin/psql/help.c
+++ b/src/bin/psql/help.c
@@ -46,11 +46,12 @@
 #define ON(var) (var ? _("on") : _("off"))
 
 void
-usage(void)
+usage(unsigned short int pager)
 {
 	const char *env;
 	const char *user;
 	char	   *errstr;
+	FILE	   *output;
 
 	/* Find default user, in case we need it. */
 	user = getenv("PGUSER");
@@ -64,77 +65,82 @@ usage(void)
 		}
 	}
 
-	printf(_("psql is the PostgreSQL interactive terminal.\n\n"));
-	printf(_("Usage:\n"));
-	printf(_("  psql [OPTION]... [DBNAME [USERNAME]]\n\n"));
+	output = PageOutput(59, pager);
+
+	fprintf(output, _("psql is the PostgreSQL interactive terminal.\n\n"));
+	fprintf(output, _("Usage:\n"));
+	fprintf(output, _("  psql [OPTION]... [DBNAME [USERNAME]]\n\n"));
 
-	printf(_("General options:\n"));
+	fprintf(output, _("General options:\n"));
 	/* Display default database */
 	env = getenv("PGDATABASE");
 	if (!env)
 		env = user;
-	printf(_("  -c, --command=COMMAND    run only single command (SQL or internal) and exit\n"));
-	printf(_("  -d, --dbname=DBNAME      database name to connect to (default: \"%s\")\n"), env);
-	printf(_("  -f, --file=FILENAME      execute commands from file, then exit\n"));
-	printf(_("  -l, --list               list available databases, then exit\n"));
-	printf(_("  -v, --set=, --variable=NAME=VALUE\n"
-			 "                           set psql variable NAME to VALUE\n"));
-	printf(_("  -V, --version            output version information, then exit\n"));
-	printf(_("  -X, --no-psqlrc          do not read startup file (~/.psqlrc)\n"));
-	printf(_("  -1 (\"one\"), --single-transaction\n"
+	fprintf(output, _("  -c, --command=COMMAND    run only single command (SQL or internal) and exit\n"));
+	fprintf(output, _("  -d, --dbname=DBNAME      database name to connect to (default: \"%s\")\n"), env);
+	fprintf(output, _("  -f, --file=FILENAME      execute commands from file, then exit\n"));
+	fprintf(output, _("  -l, --list               list available databases, then exit\n"));
+	fprintf(output, _("  -v, --set=, --variable=NAME=VALUE\n"
+			 "                           set psql variable NAME to VALUE e.g.: -v ON_ERROR_STOP=1\n"));
+	fprintf(output, _("  -V, --version            output version information, then exit\n"));
+	fprintf(output, _("  -X, --no-psqlrc          do not read startup file (~/.psqlrc)\n"));
+	fprintf(output, _("  -1 (\"one\"), --single-transaction\n"
 			 "                           execute as a single transaction (if non-interactive)\n"));
-	printf(_("  -?, --help               show this help, then exit\n"));
-
-	printf(_("\nInput and output options:\n"));
-	printf(_("  -a, --echo-all           echo all input from script\n"));
-	printf(_("  -b, --echo-errors        echo failed commands\n"));
-	printf(_("  -e, --echo-queries       echo commands sent to server\n"));
-	printf(_("  -E, --echo-hidden        display queries that internal commands generate\n"));
-	printf(_("  -L, --log-file=FILENAME  send session log to file\n"));
-	printf(_("  -n, --no-readline        disable enhanced command line editing (readline)\n"));
-	printf(_("  -o, --output=FILENAME    send query results to file (or |pipe)\n"));
-	printf(_("  -q, --quiet              run quietly (no messages, only query output)\n"));
-	printf(_("  -s, --single-step        single-step mode (confirm each query)\n"));
-	printf(_("  -S, --single-line        single-line mode (end of line terminates SQL command)\n"));
-
-	printf(_("\nOutput format options:\n"));
-	printf(_("  -A, --no-align           unaligned table output mode\n"));
-	printf(_("  -F, --field-separator=STRING\n"
+	fprintf(output, _("  -?, --help               show this help, then exit\n"));
+	fprintf(output, _("  --help-variables         show a list of all specially treated variables, then exit\n"));
+
+	fprintf(output, _("\nInput and output options:\n"));
+	fprintf(output, _("  -a, --echo-all           echo all input from script\n"));
+	fprintf(output, _("  -b, --echo-errors        echo failed commands\n"));
+	fprintf(output, _("  -e, --echo-queries       echo commands sent to server\n"));
+	fprintf(output, _("  -E, --echo-hidden        display queries that internal commands generate\n"));
+	fprintf(output, _("  -L, --log-file=FILENAME  send session log to file\n"));
+	fprintf(output, _("  -n, --no-readline        disable enhanced command line editing (readline)\n"));
+	fprintf(output, _("  -o, --output=FILENAME    send query results to file (or |pipe)\n"));
+	fprintf(output, _("  -q, --quiet              run quietly (no messages, only query output)\n"));
+	fprintf(output, _("  -s, --single-step        single-step mode (confirm each query)\n"));
+	fprintf(output, _("  -S, --single-line        single-line mode (end of line terminates SQL command)\n"));
+
+	fprintf(output, _("\nOutput format options:\n"));
+	fprintf(output, _("  -A, --no-align           unaligned table output mode\n"));
+	fprintf(output, _("  -F, --field-separator=STRING\n"
 			 "                           field separator for unaligned output (default: \"%s\")\n"),
 		   DEFAULT_FIELD_SEP);
-	printf(_("  -H, --html               HTML table output mode\n"));
-	printf(_("  -P, --pset=VAR[=ARG]     set printing option VAR to ARG (see \\pset command)\n"));
-	printf(_("  -R, --record-separator=STRING\n"
+	fprintf(output, _("  -H, --html               HTML table output mode\n"));
+	fprintf(output, _("  -P, --pset=VAR[=ARG]     set printing option VAR to ARG (see \\pset command)\n"));
+	fprintf(output, _("  -R, --record-separator=STRING\n"
 			 "                           record separator for unaligned output (default: newline)\n"));
-	printf(_("  -t, --tuples-only        print rows only\n"));
-	printf(_("  -T, --table-attr=TEXT    set HTML table tag attributes (e.g., width, border)\n"));
-	printf(_("  -x, --expanded           turn on expanded table output\n"));
-	printf(_("  -z, --field-separator-zero\n"
+	fprintf(output, _("  -t, --tuples-only        print rows only\n"));
+	fprintf(output, _("  -T, --table-attr=TEXT    set HTML table tag attributes (e.g., width, border)\n"));
+	fprintf(output, _("  -x, --expanded           turn on expanded table output\n"));
+	fprintf(output, _("  -z, --field-separator-zero\n"
 			 "                           set field separator for unaligned output to zero byte\n"));
-	printf(_("  -0, --record-separator-zero\n"
+	fprintf(output, _("  -0, --record-separator-zero\n"
 			 "                           set record separator for unaligned output to zero byte\n"));
 
-	printf(_("\nConnection options:\n"));
+	fprintf(output, _("\nConnection options:\n"));
 	/* Display default host */
 	env = getenv("PGHOST");
-	printf(_("  -h, --host=HOSTNAME      database server host or socket directory (default: \"%s\")\n"),
+	fprintf(output, _("  -h, --host=HOSTNAME      database server host or socket directory (default: \"%s\")\n"),
 		   env ? env : _("local socket"));
 	/* Display default port */
 	env = getenv("PGPORT");
-	printf(_("  -p, --port=PORT          database server port (default: \"%s\")\n"),
+	fprintf(output, _("  -p, --port=PORT          database server port (default: \"%s\")\n"),
 		   env ? env : DEF_PGPORT_STR);
 	/* Display default user */
 	env = getenv("PGUSER");
 	if (!env)
 		env = user;
-	printf(_("  -U, --username=USERNAME  database user name (default: \"%s\")\n"), env);
-	printf(_("  -w, --no-password        never prompt for password\n"));
-	printf(_("  -W, --password           force password prompt (should happen automatically)\n"));
+	fprintf(output, _("  -U, --username=USERNAME  database user name (default: \"%s\")\n"), env);
+	fprintf(output, _("  -w, --no-password        never prompt for password\n"));
+	fprintf(output, _("  -W, --password           force password prompt (should happen automatically)\n"));
 
-	printf(_("\nFor more information, type \"\\?\" (for internal commands) or \"\\help\" (for SQL\n"
+	fprintf(output, _("\nFor more information, type \"\\?\" (for internal commands) or \"\\help\" (for SQL\n"
 			 "commands) from within psql, or consult the psql section in the PostgreSQL\n"
 			 "documentation.\n\n"));
-	printf(_("Report bugs to <pgsql-bugs@postgresql.org>.\n"));
+	fprintf(output, _("Report bugs to <pgsql-bugs@postgresql.org>.\n"));
+
+	ClosePager(output);
 }
 
 
@@ -159,11 +165,18 @@ slashUsage(unsigned short int pager)
 	fprintf(output, _("  \\copyright             show PostgreSQL usage and distribution terms\n"));
 	fprintf(output, _("  \\g [FILE] or ;         execute query (and send results to file or |pipe)\n"));
 	fprintf(output, _("  \\gset [PREFIX]         execute query and store results in psql variables\n"));
-	fprintf(output, _("  \\h [NAME]              help on syntax of SQL commands, * for all commands\n"));
 	fprintf(output, _("  \\q                     quit psql\n"));
 	fprintf(output, _("  \\watch [SEC]           execute query every SEC seconds\n"));
 	fprintf(output, "\n");
 
+	fprintf(output, _("Help\n"));
+
+	fprintf(output, _("  \\?                     description of all psql commands\n"));
+	fprintf(output, _("  \\? options             description of psql options\n"));
+	fprintf(output, _("  \\? variables           description of all psql configuration variables\n"));
+	fprintf(output, _("  \\h [NAME]              help on syntax of SQL commands, * for all commands\n"));
+	fprintf(output, "\n");
+
 	fprintf(output, _("Query Buffer\n"));
 	fprintf(output, _("  \\e [FILE] [LINE]       edit the query buffer (or file) with external editor\n"));
 	fprintf(output, _("  \\ef [FUNCNAME [LINE]]  edit function definition with external editor\n"));
@@ -280,6 +293,105 @@ slashUsage(unsigned short int pager)
 }
 
 
+/*
+ * show list of available variables (options) from command line
+ */
+void
+help_variables(unsigned short int pager)
+{
+	FILE	   *output;
+
+	output = PageOutput(83, pager);
+
+	fprintf(output, _("List of specially treated variables.\n"));
+
+	fprintf(output, _("psql variables:\n"));
+	fprintf(output, _("Usage:\n"));
+	fprintf(output, _("  psql --set=NAME=VALUE\n  or \\set NAME VALUE in interactive mode\n\n"));
+
+	fprintf(output, _("  AUTOCOMMIT         if set, successful SQL commands are automatically committed\n"));
+	fprintf(output, _("  COMP_KEYWORD_CASE  determine the case used to complete SQL keywords\n"
+					 "                     [lower, upper, preserve-lower, preserve-upper]\n"));
+	fprintf(output, _("  DBNAME             the currently connected database name\n"));
+	fprintf(output, _("  ECHO               control what input is written to standard output [all, queries]\n"));
+	fprintf(output, _("  ECHO_HIDDEN        display internal queries executed by backslash commands\n"));
+	fprintf(output, _("  ENCODING           current client character set encoding\n"));
+	fprintf(output, _("  FETCH_COUNT        the number of result rows to fetch and display at a time\n"
+					 "                     (default: 0=unlimited)\n"));
+	fprintf(output, _("  HISTCONTROL        control history list [ignorespace, ignoredups, ignoreboth]\n"));
+	fprintf(output, _("  HISTFILE           file name used to store the history list\n"));
+	fprintf(output, _("  HISTSIZE           the number of commands to store in the command history\n"));
+	fprintf(output, _("  HOST               the currently connected database server\n"));
+	fprintf(output, _("  IGNOREEOF          if unset, sending an EOF to interactive session terminates application\n"));
+	fprintf(output, _("  LASTOID            the value of last affected OID\n"));
+	fprintf(output, _("  ON_ERROR_ROLLBACK  if set, an error doesn't stop a transaction (uses implicit SAVEPOINTs)\n"));
+	fprintf(output, _("  ON_ERROR_STOP      stop batch execution after error\n"));
+	fprintf(output, _("  PORT               server port of the current connection\n"));
+	fprintf(output, _("  PROMPT1, PROMPT2, PROMPT3\n"
+					 "                     specify the psql prompt\n"));
+	fprintf(output, _("  QUIET              run quietly (same as -q option)\n"));
+	fprintf(output, _("  SINGLELINE         end of line terminates SQL command mode (same as -S option)\n"));
+	fprintf(output, _("  SINGLESTEP         single-step mode (same as -s option)\n"));
+	fprintf(output, _("  USER               the currently connected database user\n"));
+	fprintf(output, _("  VERBOSITY          control verbosity of error reports [default, verbose, terse]\n"));
+
+	fprintf(output, _("\nPrinting options:\n"));
+	fprintf(output, _("Usage:\n"));
+	fprintf(output, _("  psql --pset=NAME[=VALUE]\n  or \\pset NAME [VALUE] in interactive mode\n\n"));
+
+	fprintf(output, _("  border             border style (number)\n"));
+	fprintf(output, _("  columns            set the target width for the wrapped format\n"));
+	fprintf(output, _("  expanded (or x)    toggle expanded output\n"));
+	fprintf(output, _("  fieldsep           field separator for unaligned output (default '|')\n"));
+	fprintf(output, _("  fieldsep_zero      set field separator in unaligned mode to zero\n"));
+	fprintf(output, _("  format             set output format [unaligned, aligned, wrapped, html, latex, ..]\n"));
+	fprintf(output, _("  footer             enable or disable display of the table footer [on, off]\n"));
+	fprintf(output, _("  linestyle          set the border line drawing style [ascii, old-ascii, unicode]\n"));
+	fprintf(output, _("  null               set the string to be printed in place of a null value\n"));
+	fprintf(output, _("  numericlocale      enable or disable display of a locale-specific character to separate\n"
+					 "                     groups of digits [on, off]\n"));
+	fprintf(output, _("  pager              control when an external pager is used [yes, no, always]\n"));
+	fprintf(output, _("  recordsep          specify the record (line) separator to use in unaligned output format\n"));
+	fprintf(output, _("  recordsep_zero     set the record separator to use in unaligned output format to a zero byte.\n"));
+	fprintf(output, _("  tableattr (or T)   specify attributes for table tag in html format or proportional\n"
+					 "                     column width of left aligned data type in latex format\n"));
+	fprintf(output, _("  title              set the table title for any subsequently printed tables\n"));
+	fprintf(output, _("  tuples_only        if set, only actual table data is shown\n"));
+
+	fprintf(output, _("\nEnvironment variables:\n"));
+	fprintf(output, _("Usage:\n"));
+
+#ifndef WIN32
+	fprintf(output, _("  NAME=VALUE [NAME=VALUE] psql ...\n  or \\setenv NAME [VALUE] in interactive mode\n\n"));
+#else
+	fprintf(output, _("  set NAME=VALUE\n  psql ...\n  or \\setenv NAME VALUE in interactive mode\n\n"));
+#endif
+
+	fprintf(output, _("  COLUMNS            number of columns for wrapped format\n"));
+	fprintf(output, _("  PAGER              name of external pager program\n"));
+	fprintf(output, _("  PGAPPNAME          same as the application_name connection parameter\n"));
+	fprintf(output, _("  PGDATABASE         same as the dbname connection parameter\n"));
+	fprintf(output, _("  PGHOST             same as the host connection parameter\n"));
+	fprintf(output, _("  PGPORT             same as the port connection parameter\n"));
+	fprintf(output, _("  PGUSER             same as the user connection parameter\n"));
+	fprintf(output, _("  PGPASSWORD         connection password (not recommended)\n"));
+	fprintf(output, _("  PGPASSFILE         password file name\n"));
+	fprintf(output, _("  PSQL_EDITOR, EDITOR, VISUAL\n"
+					 "                     editor used by the \\e and \\ef commands\n"));
+	fprintf(output, _("  PSQL_EDITOR_LINENUMBER_ARG\n"
+					 "                     how to specify a line number when invoking the editor\n"));
+	fprintf(output, _("  PSQL_HISTORY       alternative location for the command history file\n"));
+	fprintf(output, _("  PSQLRC             alternative location for the user's .psqlrc file\n"));
+	fprintf(output, _("  SHELL              shell used by the \\! command\n"));
+	fprintf(output, _("  TMPDIR             directory for temporary files\n"));
+
+	fprintf(output, _("\nFor more information consult the psql section in the PostgreSQL\n"
+			 "documentation.\n\n"));
+	fprintf(output, _("Report bugs to <pgsql-bugs@postgresql.org>.\n"));
+
+	ClosePager(output);
+}
+
 
 /*
  * helpSQL -- help with SQL commands
diff --git a/src/bin/psql/help.h b/src/bin/psql/help.h
index 054d5a4..bab360d 100644
--- a/src/bin/psql/help.h
+++ b/src/bin/psql/help.h
@@ -8,10 +8,12 @@
 #ifndef HELP_H
 #define HELP_H
 
-void		usage(void);
+void		usage(unsigned short int pager);
 
 void		slashUsage(unsigned short int pager);
 
+void		help_variables(unsigned short int pager);
+
 void		helpSQL(const char *topic, unsigned short int pager);
 
 void		print_copyright(void);
diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c
index 5a397e8..af68e13 100644
--- a/src/bin/psql/startup.c
+++ b/src/bin/psql/startup.c
@@ -77,6 +77,8 @@ static void process_psqlrc_file(char *filename);
 static void showVersion(void);
 static void EstablishVariableSpace(void);
 
+#define NOPAGER		0
+
 /*
  *
  * main
@@ -97,7 +99,7 @@ main(int argc, char *argv[])
 	{
 		if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
 		{
-			usage();
+			usage(NOPAGER);
 			exit(EXIT_SUCCESS);
 		}
 		if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
@@ -384,6 +386,7 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
 		{"expanded", no_argument, NULL, 'x'},
 		{"no-psqlrc", no_argument, NULL, 'X'},
 		{"help", no_argument, NULL, '?'},
+		{"help-variables", no_argument, NULL, 1},
 		{NULL, 0, NULL, 0}
 	};
 
@@ -559,7 +562,7 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
 				/* Actual help option given */
 				if (strcmp(argv[optind - 1], "--help") == 0 || strcmp(argv[optind - 1], "-?") == 0)
 				{
-					usage();
+					usage(NOPAGER);
 					exit(EXIT_SUCCESS);
 				}
 				/* unknown option reported by getopt */
@@ -570,6 +573,9 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
 					exit(EXIT_FAILURE);
 				}
 				break;
+			case 1:
+				help_variables(NOPAGER);
+				exit(EXIT_SUCCESS);
 			default:
 				fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
 						pset.progname);
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 76b2b04..7a94fa8 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -3513,6 +3513,13 @@ psql_completion(const char *text, int start, int end)
 
 /* Backslash commands */
 /* TODO:  \dc \dd \dl */
+	else if (strcmp(prev_wd, "\\?") == 0)
+	{
+		static const char *const my_list[] =
+		{"options", "variables", NULL};
+
+		COMPLETE_WITH_LIST_CS(my_list);
+	}
 	else if (strcmp(prev_wd, "\\connect") == 0 || strcmp(prev_wd, "\\c") == 0)
 		COMPLETE_WITH_QUERY(Query_for_list_of_databases);
 
#28Andres Freund
andres@2ndquadrant.com
In reply to: Pavel Stehule (#27)
1 attachment(s)

Hi,

On 2014-08-27 22:48:54 +0200, Pavel Stehule wrote:

Hi

I chose \? xxx, because it is related to psql features. I wrote commands:

\? options
\? variables

comments?

Generall I like it.

Some stuff I changed:
* I rephrased the sgml changes
* s/Printing options/Display options/. Or maybe "Display influencing
variables"? That makes it clearer why they're listed under
--help-variables.
* I added \? commands as an alias for a plain \?
That way the scheme can sensibly be expanded.
* I renamed help_variables() to be inline with the surrounding functions.

Stuff I wondered about:
* How about making it --help=variables instead of --help-variables? That
* Do we really need the 'Report bugs to' blurb for --help-variables?
* Since we're not exhaustive about documenting environment variales, do
we really need to document TMPDIR and SHELL?
* Shouldn't we document that PROMPT1 is the standard prompt, PROMPT2 is
for already started statements, and PROMPT3 is for COPY FROM STDIN?

Looks like it's commitable next round.

I've attached a incremental patch.

Greetings,

Andres Freund

--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

Attachments:

help-variables-10--11.difftext/x-diff; charset=us-asciiDownload
0001-help-variables-11.patch
#29Fujii Masao
masao.fujii@gmail.com
In reply to: Andres Freund (#28)

On Thu, Aug 28, 2014 at 8:20 PM, Andres Freund <andres@2ndquadrant.com> wrote:

Hi,

On 2014-08-27 22:48:54 +0200, Pavel Stehule wrote:

Hi

I chose \? xxx, because it is related to psql features. I wrote commands:

\? options
\? variables

comments?

Generall I like it.

Some stuff I changed:
* I rephrased the sgml changes
* s/Printing options/Display options/. Or maybe "Display influencing
variables"? That makes it clearer why they're listed under
--help-variables.
* I added \? commands as an alias for a plain \?
That way the scheme can sensibly be expanded.
* I renamed help_variables() to be inline with the surrounding functions.

Stuff I wondered about:
* How about making it --help=variables instead of --help-variables? That
* Do we really need the 'Report bugs to' blurb for --help-variables?
* Since we're not exhaustive about documenting environment variales, do
we really need to document TMPDIR and SHELL?
* Shouldn't we document that PROMPT1 is the standard prompt, PROMPT2 is
for already started statements, and PROMPT3 is for COPY FROM STDIN?

Looks like it's commitable next round.

I've attached a incremental patch.

ISTM that you failed to attach the right patch.
help-variables-10--11.diff contains only one line.

Regards,

--
Fujii Masao

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#30Andres Freund
andres@2ndquadrant.com
In reply to: Andres Freund (#28)
1 attachment(s)

On 2014-08-28 13:20:07 +0200, Andres Freund wrote:

I've attached a incremental patch.

Apparently I didn't attach the patch, as so much a file containing the
name of the patchfile...

Greetings,

Andres Freund

--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

Attachments:

help-variables-10--11.difftext/x-diff; charset=us-asciiDownload
diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index 6d3189d..b14db45 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -2581,12 +2581,15 @@ testdb=&gt; <userinput>\setenv LESS -imx4F</userinput>
 
 
       <varlistentry>
-        <term><literal>\? [ options | variables ]</literal></term>
+        <term><literal>\? [ <replaceable class="parameter">topic</replaceable> ]</literal></term>
         <listitem>
         <para>
-        Shows help information about the backslash commands.  This command can have a
-        option "variables" or "options" to take help for psql configuration variables
-        or psql command line options.
+        Shows help information. The parameter
+        <replaceable class="parameter">topic</replaceable> can be
+        <literal>commands</> (the default) to show help about backslash
+        commands, <literal>options</> to show information about commandline
+        arguments, or <literal>variables</> to show information about
+        variables influencing <application>psql</>'s behaviour or display.
         </para>
         </listitem>
       </varlistentry>
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index 12cbb20..7e4626c 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -1507,12 +1507,12 @@ exec_command(const char *cmd,
 		char	   *opt0 = psql_scan_slash_option(scan_state,
 													OT_NORMAL, NULL, false);
 
-		if (!opt0)
+		if (!opt0 || strcmp(opt0, "commands") == 0)
 			slashUsage(pset.popt.topt.pager);
-		else if (strcmp(opt0, "variables") == 0)
-			help_variables(pset.popt.topt.pager);
 		else if (strcmp(opt0, "options") == 0)
 			usage(pset.popt.topt.pager);
+		else if (strcmp(opt0, "variables") == 0)
+			helpVariables(pset.popt.topt.pager);
 		else
 			slashUsage(pset.popt.topt.pager);
 	}
diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c
index 5e7953d..e0d1d13 100644
--- a/src/bin/psql/help.c
+++ b/src/bin/psql/help.c
@@ -171,7 +171,7 @@ slashUsage(unsigned short int pager)
 
 	fprintf(output, _("Help\n"));
 
-	fprintf(output, _("  \\?                     description of all psql commands\n"));
+	fprintf(output, _("  \\? [commands]          description of all psql commands\n"));
 	fprintf(output, _("  \\? options             description of psql options\n"));
 	fprintf(output, _("  \\? variables           description of all psql configuration variables\n"));
 	fprintf(output, _("  \\h [NAME]              help on syntax of SQL commands, * for all commands\n"));
@@ -294,10 +294,12 @@ slashUsage(unsigned short int pager)
 
 
 /*
- * show list of available variables (options) from command line
+ * helpVariables
+ *
+ * Show list of available variables (options).
  */
 void
-help_variables(unsigned short int pager)
+helpVariables(unsigned short int pager)
 {
 	FILE	   *output;
 
@@ -335,7 +337,7 @@ help_variables(unsigned short int pager)
 	fprintf(output, _("  USER               the currently connected database user\n"));
 	fprintf(output, _("  VERBOSITY          control verbosity of error reports [default, verbose, terse]\n"));
 
-	fprintf(output, _("\nPrinting options:\n"));
+	fprintf(output, _("\nDisplay influencing variables:\n"));
 	fprintf(output, _("Usage:\n"));
 	fprintf(output, _("  psql --pset=NAME[=VALUE]\n  or \\pset NAME [VALUE] in interactive mode\n\n"));
 
diff --git a/src/bin/psql/help.h b/src/bin/psql/help.h
index bab360d..3ad374a 100644
--- a/src/bin/psql/help.h
+++ b/src/bin/psql/help.h
@@ -12,7 +12,7 @@ void		usage(unsigned short int pager);
 
 void		slashUsage(unsigned short int pager);
 
-void		help_variables(unsigned short int pager);
+void		helpVariables(unsigned short int pager);
 
 void		helpSQL(const char *topic, unsigned short int pager);
 
diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c
index af68e13..0651588 100644
--- a/src/bin/psql/startup.c
+++ b/src/bin/psql/startup.c
@@ -574,7 +574,7 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
 				}
 				break;
 			case 1:
-				help_variables(NOPAGER);
+				helpVariables(NOPAGER);
 				exit(EXIT_SUCCESS);
 			default:
 				fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 7a94fa8..da1b984 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -3516,7 +3516,7 @@ psql_completion(const char *text, int start, int end)
 	else if (strcmp(prev_wd, "\\?") == 0)
 	{
 		static const char *const my_list[] =
-		{"options", "variables", NULL};
+		{"commands","options", "variables", NULL};
 
 		COMPLETE_WITH_LIST_CS(my_list);
 	}
#31Pavel Stehule
pavel.stehule@gmail.com
In reply to: Andres Freund (#28)

2014-08-28 13:20 GMT+02:00 Andres Freund <andres@2ndquadrant.com>:

Hi,

On 2014-08-27 22:48:54 +0200, Pavel Stehule wrote:

Hi

I chose \? xxx, because it is related to psql features. I wrote commands:

\? options
\? variables

comments?

Generall I like it.

Some stuff I changed:
* I rephrased the sgml changes
* s/Printing options/Display options/. Or maybe "Display influencing
variables"? That makes it clearer why they're listed under
--help-variables.
* I added \? commands as an alias for a plain \?
That way the scheme can sensibly be expanded.
* I renamed help_variables() to be inline with the surrounding functions.

Stuff I wondered about:
* How about making it --help=variables instead of --help-variables? That

I am sorry, I don't like this idea --help-variables is much more usual for
cmd line

* Do we really need the 'Report bugs to' blurb for --help-variables?

* Since we're not exhaustive about documenting environment variales, do
we really need to document TMPDIR and SHELL?
* Shouldn't we document that PROMPT1 is the standard prompt, PROMPT2 is
for already started statements, and PROMPT3 is for COPY FROM STDIN?

I don't see TMPDIR, SHELL as really important in this position

Pavel

Show quoted text

Looks like it's commitable next round.

I've attached a incremental patch.

Greetings,

Andres Freund

--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

#32Petr Jelinek
petr@2ndquadrant.com
In reply to: Andres Freund (#28)

On 28/08/14 13:20, Andres Freund wrote:

Hi,

Stuff I wondered about:
* How about making it --help=variables instead of --help-variables?

-1, help is not a variable to be assigned imho

* Do we really need the 'Report bugs to' blurb for --help-variables?

Probably not.

* Since we're not exhaustive about documenting environment variales, do
we really need to document TMPDIR and SHELL?

They are bit more important than most of others, but probably not really
necessary to be there as they are not psql specific.

* Shouldn't we document that PROMPT1 is the standard prompt, PROMPT2 is
for already started statements, and PROMPT3 is for COPY FROM STDIN?

Yes please!

--
Petr Jelinek http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#33Fujii Masao
masao.fujii@gmail.com
In reply to: Pavel Stehule (#27)

On Thu, Aug 28, 2014 at 5:48 AM, Pavel Stehule <pavel.stehule@gmail.com> wrote:

comments?

+ fprintf(output, _(" ECHO control what input is
written to standard output [all, queries]\n"));

The valid values in the help messages should be consistent with
the values that the tab-completion displays. So in the case of ECHO,
"errors" and "none" also should be added in the message. Thought?

In the help messages of some psql variables like ECHO_HIDDEN, valid
values are not explained. Why not?

Regards,

--
Fujii Masao

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#34Pavel Stehule
pavel.stehule@gmail.com
In reply to: Fujii Masao (#33)

2014-08-28 14:22 GMT+02:00 Fujii Masao <masao.fujii@gmail.com>:

On Thu, Aug 28, 2014 at 5:48 AM, Pavel Stehule <pavel.stehule@gmail.com>
wrote:

comments?

+ fprintf(output, _(" ECHO control what input is
written to standard output [all, queries]\n"));

The valid values in the help messages should be consistent with
the values that the tab-completion displays. So in the case of ECHO,
"errors" and "none" also should be added in the message. Thought?

In the help messages of some psql variables like ECHO_HIDDEN, valid
values are not explained. Why not?

it is based on http://www.postgresql.org/docs/9.4/static/app-psql.html

ECHO_HIDDEN

When this variable is set and a backslash command queries the database, the
query is first shown. This way you can study the PostgreSQL internals and
provide similar functionality in your own programs. (To select this
behavior on program start-up, use the switch -E.) If you set the variable
to the value noexec, the queries are just shown but are not actually sent
to the server and executed.
There are no clear a set of valid values :( .. When I found a known fields
in doc, I used it.

Regards

Pavel

Show quoted text

Regards,

--
Fujii Masao

#35Andres Freund
andres@2ndquadrant.com
In reply to: Petr Jelinek (#32)

On 2014-08-28 14:04:27 +0200, Petr Jelinek wrote:

On 28/08/14 13:20, Andres Freund wrote:

Hi,

Stuff I wondered about:
* How about making it --help=variables instead of --help-variables?

-1, help is not a variable to be assigned imho

I don't think variable assignment is a good mental model for long
commandline arguments. And it's not like I'm the first to come up with
an extensible --help. Check e.g. gcc.

But anyway, I guess I've lost that argument.

Greetings,

Andres Freund

--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#36Fujii Masao
masao.fujii@gmail.com
In reply to: Pavel Stehule (#34)

On Thu, Aug 28, 2014 at 9:34 PM, Pavel Stehule <pavel.stehule@gmail.com> wrote:

2014-08-28 14:22 GMT+02:00 Fujii Masao <masao.fujii@gmail.com>:

On Thu, Aug 28, 2014 at 5:48 AM, Pavel Stehule <pavel.stehule@gmail.com>
wrote:

comments?

+ fprintf(output, _(" ECHO control what input is
written to standard output [all, queries]\n"));

The valid values in the help messages should be consistent with
the values that the tab-completion displays. So in the case of ECHO,
"errors" and "none" also should be added in the message. Thought?

In the help messages of some psql variables like ECHO_HIDDEN, valid
values are not explained. Why not?

it is based on http://www.postgresql.org/docs/9.4/static/app-psql.html

ECHO_HIDDEN

When this variable is set and a backslash command queries the database, the
query is first shown. This way you can study the PostgreSQL internals and
provide similar functionality in your own programs. (To select this behavior
on program start-up, use the switch -E.) If you set the variable to the
value noexec, the queries are just shown but are not actually sent to the
server and executed.

There are no clear a set of valid values :( .. When I found a known fields
in doc, I used it.

At least "noexec" seems to be documented as a valid value. Of course,
it's better to document other valid values.

Regards,

--
Fujii Masao

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#37Pavel Stehule
pavel.stehule@gmail.com
In reply to: Fujii Masao (#36)
1 attachment(s)

Hello

fixed ECHO, ECHO_HIDDEN, PROPMPT

Regards

Pavel

2014-09-01 11:52 GMT+02:00 Fujii Masao <masao.fujii@gmail.com>:

Show quoted text

On Thu, Aug 28, 2014 at 9:34 PM, Pavel Stehule <pavel.stehule@gmail.com>
wrote:

2014-08-28 14:22 GMT+02:00 Fujii Masao <masao.fujii@gmail.com>:

On Thu, Aug 28, 2014 at 5:48 AM, Pavel Stehule <pavel.stehule@gmail.com

wrote:

comments?

+ fprintf(output, _(" ECHO control what input is
written to standard output [all, queries]\n"));

The valid values in the help messages should be consistent with
the values that the tab-completion displays. So in the case of ECHO,
"errors" and "none" also should be added in the message. Thought?

In the help messages of some psql variables like ECHO_HIDDEN, valid
values are not explained. Why not?

it is based on http://www.postgresql.org/docs/9.4/static/app-psql.html

ECHO_HIDDEN

When this variable is set and a backslash command queries the database,

the

query is first shown. This way you can study the PostgreSQL internals and
provide similar functionality in your own programs. (To select this

behavior

on program start-up, use the switch -E.) If you set the variable to the
value noexec, the queries are just shown but are not actually sent to the
server and executed.

There are no clear a set of valid values :( .. When I found a known

fields

in doc, I used it.

At least "noexec" seems to be documented as a valid value. Of course,
it's better to document other valid values.

Regards,

--
Fujii Masao

Attachments:

help-variables-11.patchtext/x-patch; charset=US-ASCII; name=help-variables-11.patchDownload
commit 17a0708a0466cc8ff9e8debd0a7e9062eebe3a61
Author: Pavel Stehule <pavel.stehule@gooddata.com>
Date:   Wed Aug 27 22:47:07 2014 +0200

    access to help_variables and usage from psql via psql command

diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index db314c3..9bb14e9 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -568,6 +568,15 @@ EOF
       </listitem>
     </varlistentry>
 
+    <varlistentry>
+      <term><option>--help-variables</></term>
+      <listitem>
+      <para>
+      Show help about <application>psql</application> variables,
+      and exit.
+      </para>
+      </listitem>
+    </varlistentry>
   </variablelist>
  </refsect1>
 
@@ -2572,10 +2581,12 @@ testdb=&gt; <userinput>\setenv LESS -imx4F</userinput>
 
 
       <varlistentry>
-        <term><literal>\?</literal></term>
+        <term><literal>\? [ options | variables ]</literal></term>
         <listitem>
         <para>
-        Shows help information about the backslash commands.
+        Shows help information about the backslash commands.  This command can have a
+        option "variables" or "options" to take help for psql configuration variables
+        or psql command line options.
         </para>
         </listitem>
       </varlistentry>
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index e16b4d5..987a79f 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -1503,7 +1503,19 @@ exec_command(const char *cmd,
 
 	/* \? -- slash command help */
 	else if (strcmp(cmd, "?") == 0)
-		slashUsage(pset.popt.topt.pager);
+	{
+		char	   *opt0 = psql_scan_slash_option(scan_state,
+													OT_NORMAL, NULL, false);
+
+		if (!opt0)
+			slashUsage(pset.popt.topt.pager);
+		else if (strcmp(opt0, "variables") == 0)
+			help_variables(pset.popt.topt.pager);
+		else if (strcmp(opt0, "options") == 0)
+			usage(pset.popt.topt.pager);
+		else
+			slashUsage(pset.popt.topt.pager);
+	}
 
 #if 0
 
diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c
index f8f000f..4f29f2a 100644
--- a/src/bin/psql/help.c
+++ b/src/bin/psql/help.c
@@ -46,11 +46,12 @@
 #define ON(var) (var ? _("on") : _("off"))
 
 void
-usage(void)
+usage(unsigned short int pager)
 {
 	const char *env;
 	const char *user;
 	char	   *errstr;
+	FILE	   *output;
 
 	/* Find default user, in case we need it. */
 	user = getenv("PGUSER");
@@ -64,77 +65,82 @@ usage(void)
 		}
 	}
 
-	printf(_("psql is the PostgreSQL interactive terminal.\n\n"));
-	printf(_("Usage:\n"));
-	printf(_("  psql [OPTION]... [DBNAME [USERNAME]]\n\n"));
+	output = PageOutput(59, pager);
+
+	fprintf(output, _("psql is the PostgreSQL interactive terminal.\n\n"));
+	fprintf(output, _("Usage:\n"));
+	fprintf(output, _("  psql [OPTION]... [DBNAME [USERNAME]]\n\n"));
 
-	printf(_("General options:\n"));
+	fprintf(output, _("General options:\n"));
 	/* Display default database */
 	env = getenv("PGDATABASE");
 	if (!env)
 		env = user;
-	printf(_("  -c, --command=COMMAND    run only single command (SQL or internal) and exit\n"));
-	printf(_("  -d, --dbname=DBNAME      database name to connect to (default: \"%s\")\n"), env);
-	printf(_("  -f, --file=FILENAME      execute commands from file, then exit\n"));
-	printf(_("  -l, --list               list available databases, then exit\n"));
-	printf(_("  -v, --set=, --variable=NAME=VALUE\n"
-			 "                           set psql variable NAME to VALUE\n"));
-	printf(_("  -V, --version            output version information, then exit\n"));
-	printf(_("  -X, --no-psqlrc          do not read startup file (~/.psqlrc)\n"));
-	printf(_("  -1 (\"one\"), --single-transaction\n"
+	fprintf(output, _("  -c, --command=COMMAND    run only single command (SQL or internal) and exit\n"));
+	fprintf(output, _("  -d, --dbname=DBNAME      database name to connect to (default: \"%s\")\n"), env);
+	fprintf(output, _("  -f, --file=FILENAME      execute commands from file, then exit\n"));
+	fprintf(output, _("  -l, --list               list available databases, then exit\n"));
+	fprintf(output, _("  -v, --set=, --variable=NAME=VALUE\n"
+			 "                           set psql variable NAME to VALUE e.g.: -v ON_ERROR_STOP=1\n"));
+	fprintf(output, _("  -V, --version            output version information, then exit\n"));
+	fprintf(output, _("  -X, --no-psqlrc          do not read startup file (~/.psqlrc)\n"));
+	fprintf(output, _("  -1 (\"one\"), --single-transaction\n"
 			 "                           execute as a single transaction (if non-interactive)\n"));
-	printf(_("  -?, --help               show this help, then exit\n"));
-
-	printf(_("\nInput and output options:\n"));
-	printf(_("  -a, --echo-all           echo all input from script\n"));
-	printf(_("  -b, --echo-errors        echo failed commands\n"));
-	printf(_("  -e, --echo-queries       echo commands sent to server\n"));
-	printf(_("  -E, --echo-hidden        display queries that internal commands generate\n"));
-	printf(_("  -L, --log-file=FILENAME  send session log to file\n"));
-	printf(_("  -n, --no-readline        disable enhanced command line editing (readline)\n"));
-	printf(_("  -o, --output=FILENAME    send query results to file (or |pipe)\n"));
-	printf(_("  -q, --quiet              run quietly (no messages, only query output)\n"));
-	printf(_("  -s, --single-step        single-step mode (confirm each query)\n"));
-	printf(_("  -S, --single-line        single-line mode (end of line terminates SQL command)\n"));
-
-	printf(_("\nOutput format options:\n"));
-	printf(_("  -A, --no-align           unaligned table output mode\n"));
-	printf(_("  -F, --field-separator=STRING\n"
+	fprintf(output, _("  -?, --help               show this help, then exit\n"));
+	fprintf(output, _("  --help-variables         show a list of all specially treated variables, then exit\n"));
+
+	fprintf(output, _("\nInput and output options:\n"));
+	fprintf(output, _("  -a, --echo-all           echo all input from script\n"));
+	fprintf(output, _("  -b, --echo-errors        echo failed commands\n"));
+	fprintf(output, _("  -e, --echo-queries       echo commands sent to server\n"));
+	fprintf(output, _("  -E, --echo-hidden        display queries that internal commands generate\n"));
+	fprintf(output, _("  -L, --log-file=FILENAME  send session log to file\n"));
+	fprintf(output, _("  -n, --no-readline        disable enhanced command line editing (readline)\n"));
+	fprintf(output, _("  -o, --output=FILENAME    send query results to file (or |pipe)\n"));
+	fprintf(output, _("  -q, --quiet              run quietly (no messages, only query output)\n"));
+	fprintf(output, _("  -s, --single-step        single-step mode (confirm each query)\n"));
+	fprintf(output, _("  -S, --single-line        single-line mode (end of line terminates SQL command)\n"));
+
+	fprintf(output, _("\nOutput format options:\n"));
+	fprintf(output, _("  -A, --no-align           unaligned table output mode\n"));
+	fprintf(output, _("  -F, --field-separator=STRING\n"
 			 "                           field separator for unaligned output (default: \"%s\")\n"),
 		   DEFAULT_FIELD_SEP);
-	printf(_("  -H, --html               HTML table output mode\n"));
-	printf(_("  -P, --pset=VAR[=ARG]     set printing option VAR to ARG (see \\pset command)\n"));
-	printf(_("  -R, --record-separator=STRING\n"
+	fprintf(output, _("  -H, --html               HTML table output mode\n"));
+	fprintf(output, _("  -P, --pset=VAR[=ARG]     set printing option VAR to ARG (see \\pset command)\n"));
+	fprintf(output, _("  -R, --record-separator=STRING\n"
 			 "                           record separator for unaligned output (default: newline)\n"));
-	printf(_("  -t, --tuples-only        print rows only\n"));
-	printf(_("  -T, --table-attr=TEXT    set HTML table tag attributes (e.g., width, border)\n"));
-	printf(_("  -x, --expanded           turn on expanded table output\n"));
-	printf(_("  -z, --field-separator-zero\n"
+	fprintf(output, _("  -t, --tuples-only        print rows only\n"));
+	fprintf(output, _("  -T, --table-attr=TEXT    set HTML table tag attributes (e.g., width, border)\n"));
+	fprintf(output, _("  -x, --expanded           turn on expanded table output\n"));
+	fprintf(output, _("  -z, --field-separator-zero\n"
 			 "                           set field separator for unaligned output to zero byte\n"));
-	printf(_("  -0, --record-separator-zero\n"
+	fprintf(output, _("  -0, --record-separator-zero\n"
 			 "                           set record separator for unaligned output to zero byte\n"));
 
-	printf(_("\nConnection options:\n"));
+	fprintf(output, _("\nConnection options:\n"));
 	/* Display default host */
 	env = getenv("PGHOST");
-	printf(_("  -h, --host=HOSTNAME      database server host or socket directory (default: \"%s\")\n"),
+	fprintf(output, _("  -h, --host=HOSTNAME      database server host or socket directory (default: \"%s\")\n"),
 		   env ? env : _("local socket"));
 	/* Display default port */
 	env = getenv("PGPORT");
-	printf(_("  -p, --port=PORT          database server port (default: \"%s\")\n"),
+	fprintf(output, _("  -p, --port=PORT          database server port (default: \"%s\")\n"),
 		   env ? env : DEF_PGPORT_STR);
 	/* Display default user */
 	env = getenv("PGUSER");
 	if (!env)
 		env = user;
-	printf(_("  -U, --username=USERNAME  database user name (default: \"%s\")\n"), env);
-	printf(_("  -w, --no-password        never prompt for password\n"));
-	printf(_("  -W, --password           force password prompt (should happen automatically)\n"));
+	fprintf(output, _("  -U, --username=USERNAME  database user name (default: \"%s\")\n"), env);
+	fprintf(output, _("  -w, --no-password        never prompt for password\n"));
+	fprintf(output, _("  -W, --password           force password prompt (should happen automatically)\n"));
 
-	printf(_("\nFor more information, type \"\\?\" (for internal commands) or \"\\help\" (for SQL\n"
+	fprintf(output, _("\nFor more information, type \"\\?\" (for internal commands) or \"\\help\" (for SQL\n"
 			 "commands) from within psql, or consult the psql section in the PostgreSQL\n"
 			 "documentation.\n\n"));
-	printf(_("Report bugs to <pgsql-bugs@postgresql.org>.\n"));
+	fprintf(output, _("Report bugs to <pgsql-bugs@postgresql.org>.\n"));
+
+	ClosePager(output);
 }
 
 
@@ -159,11 +165,18 @@ slashUsage(unsigned short int pager)
 	fprintf(output, _("  \\copyright             show PostgreSQL usage and distribution terms\n"));
 	fprintf(output, _("  \\g [FILE] or ;         execute query (and send results to file or |pipe)\n"));
 	fprintf(output, _("  \\gset [PREFIX]         execute query and store results in psql variables\n"));
-	fprintf(output, _("  \\h [NAME]              help on syntax of SQL commands, * for all commands\n"));
 	fprintf(output, _("  \\q                     quit psql\n"));
 	fprintf(output, _("  \\watch [SEC]           execute query every SEC seconds\n"));
 	fprintf(output, "\n");
 
+	fprintf(output, _("Help\n"));
+
+	fprintf(output, _("  \\?                     description of all psql commands\n"));
+	fprintf(output, _("  \\? options             description of psql options\n"));
+	fprintf(output, _("  \\? variables           description of all psql configuration variables\n"));
+	fprintf(output, _("  \\h [NAME]              help on syntax of SQL commands, * for all commands\n"));
+	fprintf(output, "\n");
+
 	fprintf(output, _("Query Buffer\n"));
 	fprintf(output, _("  \\e [FILE] [LINE]       edit the query buffer (or file) with external editor\n"));
 	fprintf(output, _("  \\ef [FUNCNAME [LINE]]  edit function definition with external editor\n"));
@@ -280,6 +293,108 @@ slashUsage(unsigned short int pager)
 }
 
 
+/*
+ * show list of available variables (options) from command line
+ */
+void
+help_variables(unsigned short int pager)
+{
+	FILE	   *output;
+
+	output = PageOutput(86, pager);
+
+	fprintf(output, _("List of specially treated variables.\n"));
+
+	fprintf(output, _("psql variables:\n"));
+	fprintf(output, _("Usage:\n"));
+	fprintf(output, _("  psql --set=NAME=VALUE\n  or \\set NAME VALUE in interactive mode\n\n"));
+
+	fprintf(output, _("  AUTOCOMMIT         if set, successful SQL commands are automatically committed\n"));
+	fprintf(output, _("  COMP_KEYWORD_CASE  determine the case used to complete SQL keywords\n"
+					 "                     [lower, upper, preserve-lower, preserve-upper]\n"));
+	fprintf(output, _("  DBNAME             the currently connected database name\n"));
+	fprintf(output, _("  ECHO               control what input is written to standard output\n"
+					 "                     [all, errors, none, queries]\n"));
+	fprintf(output, _("  ECHO_HIDDEN        display internal queries executed by backslash commands when it is set\n"
+					 "                     or with [noexec] just show without execution\n"));
+	fprintf(output, _("  ENCODING           current client character set encoding\n"));
+	fprintf(output, _("  FETCH_COUNT        the number of result rows to fetch and display at a time\n"
+					 "                     (default: 0=unlimited)\n"));
+	fprintf(output, _("  HISTCONTROL        control history list [ignorespace, ignoredups, ignoreboth]\n"));
+	fprintf(output, _("  HISTFILE           file name used to store the history list\n"));
+	fprintf(output, _("  HISTSIZE           the number of commands to store in the command history\n"));
+	fprintf(output, _("  HOST               the currently connected database server\n"));
+	fprintf(output, _("  IGNOREEOF          if unset, sending an EOF to interactive session terminates application\n"));
+	fprintf(output, _("  LASTOID            the value of last affected OID\n"));
+	fprintf(output, _("  ON_ERROR_ROLLBACK  if set, an error doesn't stop a transaction (uses implicit SAVEPOINTs)\n"));
+	fprintf(output, _("  ON_ERROR_STOP      stop batch execution after error\n"));
+	fprintf(output, _("  PORT               server port of the current connection\n"));
+	fprintf(output, _("  PROMPT1            specify standard the psql prompt\n"));
+	fprintf(output, _("  PROMPT2            specify the psql prompt when statement continues from previous line\n"));
+	fprintf(output, _("  PROMPT3            specify the psql prompt used by COPY statement\n"));
+	fprintf(output, _("  QUIET              run quietly (same as -q option)\n"));
+	fprintf(output, _("  SINGLELINE         end of line terminates SQL command mode (same as -S option)\n"));
+	fprintf(output, _("  SINGLESTEP         single-step mode (same as -s option)\n"));
+	fprintf(output, _("  USER               the currently connected database user\n"));
+	fprintf(output, _("  VERBOSITY          control verbosity of error reports [default, verbose, terse]\n"));
+
+	fprintf(output, _("\nPrinting options:\n"));
+	fprintf(output, _("Usage:\n"));
+	fprintf(output, _("  psql --pset=NAME[=VALUE]\n  or \\pset NAME [VALUE] in interactive mode\n\n"));
+
+	fprintf(output, _("  border             border style (number)\n"));
+	fprintf(output, _("  columns            set the target width for the wrapped format\n"));
+	fprintf(output, _("  expanded (or x)    toggle expanded output\n"));
+	fprintf(output, _("  fieldsep           field separator for unaligned output (default '|')\n"));
+	fprintf(output, _("  fieldsep_zero      set field separator in unaligned mode to zero\n"));
+	fprintf(output, _("  format             set output format [unaligned, aligned, wrapped, html, latex, ..]\n"));
+	fprintf(output, _("  footer             enable or disable display of the table footer [on, off]\n"));
+	fprintf(output, _("  linestyle          set the border line drawing style [ascii, old-ascii, unicode]\n"));
+	fprintf(output, _("  null               set the string to be printed in place of a null value\n"));
+	fprintf(output, _("  numericlocale      enable or disable display of a locale-specific character to separate\n"
+					 "                     groups of digits [on, off]\n"));
+	fprintf(output, _("  pager              control when an external pager is used [yes, no, always]\n"));
+	fprintf(output, _("  recordsep          specify the record (line) separator to use in unaligned output format\n"));
+	fprintf(output, _("  recordsep_zero     set the record separator to use in unaligned output format to a zero byte.\n"));
+	fprintf(output, _("  tableattr (or T)   specify attributes for table tag in html format or proportional\n"
+					 "                     column width of left aligned data type in latex format\n"));
+	fprintf(output, _("  title              set the table title for any subsequently printed tables\n"));
+	fprintf(output, _("  tuples_only        if set, only actual table data is shown\n"));
+
+	fprintf(output, _("\nEnvironment variables:\n"));
+	fprintf(output, _("Usage:\n"));
+
+#ifndef WIN32
+	fprintf(output, _("  NAME=VALUE [NAME=VALUE] psql ...\n  or \\setenv NAME [VALUE] in interactive mode\n\n"));
+#else
+	fprintf(output, _("  set NAME=VALUE\n  psql ...\n  or \\setenv NAME VALUE in interactive mode\n\n"));
+#endif
+
+	fprintf(output, _("  COLUMNS            number of columns for wrapped format\n"));
+	fprintf(output, _("  PAGER              name of external pager program\n"));
+	fprintf(output, _("  PGAPPNAME          same as the application_name connection parameter\n"));
+	fprintf(output, _("  PGDATABASE         same as the dbname connection parameter\n"));
+	fprintf(output, _("  PGHOST             same as the host connection parameter\n"));
+	fprintf(output, _("  PGPORT             same as the port connection parameter\n"));
+	fprintf(output, _("  PGUSER             same as the user connection parameter\n"));
+	fprintf(output, _("  PGPASSWORD         connection password (not recommended)\n"));
+	fprintf(output, _("  PGPASSFILE         password file name\n"));
+	fprintf(output, _("  PSQL_EDITOR, EDITOR, VISUAL\n"
+					 "                     editor used by the \\e and \\ef commands\n"));
+	fprintf(output, _("  PSQL_EDITOR_LINENUMBER_ARG\n"
+					 "                     how to specify a line number when invoking the editor\n"));
+	fprintf(output, _("  PSQL_HISTORY       alternative location for the command history file\n"));
+	fprintf(output, _("  PSQLRC             alternative location for the user's .psqlrc file\n"));
+	fprintf(output, _("  SHELL              shell used by the \\! command\n"));
+	fprintf(output, _("  TMPDIR             directory for temporary files\n"));
+
+	fprintf(output, _("\nFor more information consult the psql section in the PostgreSQL\n"
+			 "documentation.\n\n"));
+	fprintf(output, _("Report bugs to <pgsql-bugs@postgresql.org>.\n"));
+
+	ClosePager(output);
+}
+
 
 /*
  * helpSQL -- help with SQL commands
diff --git a/src/bin/psql/help.h b/src/bin/psql/help.h
index 054d5a4..bab360d 100644
--- a/src/bin/psql/help.h
+++ b/src/bin/psql/help.h
@@ -8,10 +8,12 @@
 #ifndef HELP_H
 #define HELP_H
 
-void		usage(void);
+void		usage(unsigned short int pager);
 
 void		slashUsage(unsigned short int pager);
 
+void		help_variables(unsigned short int pager);
+
 void		helpSQL(const char *topic, unsigned short int pager);
 
 void		print_copyright(void);
diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c
index 5a397e8..af68e13 100644
--- a/src/bin/psql/startup.c
+++ b/src/bin/psql/startup.c
@@ -77,6 +77,8 @@ static void process_psqlrc_file(char *filename);
 static void showVersion(void);
 static void EstablishVariableSpace(void);
 
+#define NOPAGER		0
+
 /*
  *
  * main
@@ -97,7 +99,7 @@ main(int argc, char *argv[])
 	{
 		if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
 		{
-			usage();
+			usage(NOPAGER);
 			exit(EXIT_SUCCESS);
 		}
 		if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
@@ -384,6 +386,7 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
 		{"expanded", no_argument, NULL, 'x'},
 		{"no-psqlrc", no_argument, NULL, 'X'},
 		{"help", no_argument, NULL, '?'},
+		{"help-variables", no_argument, NULL, 1},
 		{NULL, 0, NULL, 0}
 	};
 
@@ -559,7 +562,7 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
 				/* Actual help option given */
 				if (strcmp(argv[optind - 1], "--help") == 0 || strcmp(argv[optind - 1], "-?") == 0)
 				{
-					usage();
+					usage(NOPAGER);
 					exit(EXIT_SUCCESS);
 				}
 				/* unknown option reported by getopt */
@@ -570,6 +573,9 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
 					exit(EXIT_FAILURE);
 				}
 				break;
+			case 1:
+				help_variables(NOPAGER);
+				exit(EXIT_SUCCESS);
 			default:
 				fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
 						pset.progname);
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 8288b41..ec6182b 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -3524,6 +3524,13 @@ psql_completion(const char *text, int start, int end)
 
 /* Backslash commands */
 /* TODO:  \dc \dd \dl */
+	else if (strcmp(prev_wd, "\\?") == 0)
+	{
+		static const char *const my_list[] =
+		{"options", "variables", NULL};
+
+		COMPLETE_WITH_LIST_CS(my_list);
+	}
 	else if (strcmp(prev_wd, "\\connect") == 0 || strcmp(prev_wd, "\\c") == 0)
 		COMPLETE_WITH_QUERY(Query_for_list_of_databases);
 
#38Robert Haas
robertmhaas@gmail.com
In reply to: Andres Freund (#35)

On Thu, Aug 28, 2014 at 11:20 AM, Andres Freund <andres@2ndquadrant.com> wrote:

* How about making it --help=variables instead of --help-variables?

-1, help is not a variable to be assigned imho

I don't think variable assignment is a good mental model for long
commandline arguments. And it's not like I'm the first to come up with
an extensible --help. Check e.g. gcc.

But anyway, I guess I've lost that argument.

I think it mostly depends on how far we think we might extend it. I
mean, --help-variables is fine as a parallel to --help. But if we're
eventually going to have help for 12 things, --help=TOPIC is a lot
better than 12 separate switches. So +0.5 for your proposal from me.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#39Pavel Stehule
pavel.stehule@gmail.com
In reply to: Robert Haas (#38)
1 attachment(s)

Hi

here is a second variant with support --help=variables

Regards

Pavel

2014-09-04 4:25 GMT+02:00 Robert Haas <robertmhaas@gmail.com>:

Show quoted text

On Thu, Aug 28, 2014 at 11:20 AM, Andres Freund <andres@2ndquadrant.com>
wrote:

* How about making it --help=variables instead of --help-variables?

-1, help is not a variable to be assigned imho

I don't think variable assignment is a good mental model for long
commandline arguments. And it's not like I'm the first to come up with
an extensible --help. Check e.g. gcc.

But anyway, I guess I've lost that argument.

I think it mostly depends on how far we think we might extend it. I
mean, --help-variables is fine as a parallel to --help. But if we're
eventually going to have help for 12 things, --help=TOPIC is a lot
better than 12 separate switches. So +0.5 for your proposal from me.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

Attachments:

help-variables-12.patchtext/x-patch; charset=US-ASCII; name=help-variables-12.patchDownload
commit cac76b6135ae9f4b3c1eab1ce6bc34b43a7506ef
Author: Pavel Stehule <pavel.stehule@gooddata.com>
Date:   Wed Aug 27 22:47:07 2014 +0200

    access to help_variables and usage from psql via psql command

diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index db314c3..05a0f01 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -560,11 +560,18 @@ EOF
     <varlistentry>
       <term><option>-?</></term>
       <term><option>--help</></term>
+      <term><option>--help=<replaceable class="parameter">topic</replaceable></option></term>
       <listitem>
       <para>
       Show help about <application>psql</application> command line
       arguments, and exit.
       </para>
+
+      <para>
+      <option>--help=variables</>show help about <application>psql</application> variables,
+      and exit.
+      </para>
+
       </listitem>
     </varlistentry>
 
@@ -2572,10 +2579,12 @@ testdb=&gt; <userinput>\setenv LESS -imx4F</userinput>
 
 
       <varlistentry>
-        <term><literal>\?</literal></term>
+        <term><literal>\? [ options | variables ]</literal></term>
         <listitem>
         <para>
-        Shows help information about the backslash commands.
+        Shows help information about the backslash commands.  This command can have a
+        option "variables" or "options" to take help for psql configuration variables
+        or psql command line options.
         </para>
         </listitem>
       </varlistentry>
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index e16b4d5..987a79f 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -1503,7 +1503,19 @@ exec_command(const char *cmd,
 
 	/* \? -- slash command help */
 	else if (strcmp(cmd, "?") == 0)
-		slashUsage(pset.popt.topt.pager);
+	{
+		char	   *opt0 = psql_scan_slash_option(scan_state,
+													OT_NORMAL, NULL, false);
+
+		if (!opt0)
+			slashUsage(pset.popt.topt.pager);
+		else if (strcmp(opt0, "variables") == 0)
+			help_variables(pset.popt.topt.pager);
+		else if (strcmp(opt0, "options") == 0)
+			usage(pset.popt.topt.pager);
+		else
+			slashUsage(pset.popt.topt.pager);
+	}
 
 #if 0
 
diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c
index f8f000f..0ada015 100644
--- a/src/bin/psql/help.c
+++ b/src/bin/psql/help.c
@@ -46,11 +46,12 @@
 #define ON(var) (var ? _("on") : _("off"))
 
 void
-usage(void)
+usage(unsigned short int pager)
 {
 	const char *env;
 	const char *user;
 	char	   *errstr;
+	FILE	   *output;
 
 	/* Find default user, in case we need it. */
 	user = getenv("PGUSER");
@@ -64,77 +65,82 @@ usage(void)
 		}
 	}
 
-	printf(_("psql is the PostgreSQL interactive terminal.\n\n"));
-	printf(_("Usage:\n"));
-	printf(_("  psql [OPTION]... [DBNAME [USERNAME]]\n\n"));
+	output = PageOutput(59, pager);
+
+	fprintf(output, _("psql is the PostgreSQL interactive terminal.\n\n"));
+	fprintf(output, _("Usage:\n"));
+	fprintf(output, _("  psql [OPTION]... [DBNAME [USERNAME]]\n\n"));
 
-	printf(_("General options:\n"));
+	fprintf(output, _("General options:\n"));
 	/* Display default database */
 	env = getenv("PGDATABASE");
 	if (!env)
 		env = user;
-	printf(_("  -c, --command=COMMAND    run only single command (SQL or internal) and exit\n"));
-	printf(_("  -d, --dbname=DBNAME      database name to connect to (default: \"%s\")\n"), env);
-	printf(_("  -f, --file=FILENAME      execute commands from file, then exit\n"));
-	printf(_("  -l, --list               list available databases, then exit\n"));
-	printf(_("  -v, --set=, --variable=NAME=VALUE\n"
-			 "                           set psql variable NAME to VALUE\n"));
-	printf(_("  -V, --version            output version information, then exit\n"));
-	printf(_("  -X, --no-psqlrc          do not read startup file (~/.psqlrc)\n"));
-	printf(_("  -1 (\"one\"), --single-transaction\n"
+	fprintf(output, _("  -c, --command=COMMAND    run only single command (SQL or internal) and exit\n"));
+	fprintf(output, _("  -d, --dbname=DBNAME      database name to connect to (default: \"%s\")\n"), env);
+	fprintf(output, _("  -f, --file=FILENAME      execute commands from file, then exit\n"));
+	fprintf(output, _("  -l, --list               list available databases, then exit\n"));
+	fprintf(output, _("  -v, --set=, --variable=NAME=VALUE\n"
+			 "                           set psql variable NAME to VALUE e.g.: -v ON_ERROR_STOP=1\n"));
+	fprintf(output, _("  -V, --version            output version information, then exit\n"));
+	fprintf(output, _("  -X, --no-psqlrc          do not read startup file (~/.psqlrc)\n"));
+	fprintf(output, _("  -1 (\"one\"), --single-transaction\n"
 			 "                           execute as a single transaction (if non-interactive)\n"));
-	printf(_("  -?, --help               show this help, then exit\n"));
-
-	printf(_("\nInput and output options:\n"));
-	printf(_("  -a, --echo-all           echo all input from script\n"));
-	printf(_("  -b, --echo-errors        echo failed commands\n"));
-	printf(_("  -e, --echo-queries       echo commands sent to server\n"));
-	printf(_("  -E, --echo-hidden        display queries that internal commands generate\n"));
-	printf(_("  -L, --log-file=FILENAME  send session log to file\n"));
-	printf(_("  -n, --no-readline        disable enhanced command line editing (readline)\n"));
-	printf(_("  -o, --output=FILENAME    send query results to file (or |pipe)\n"));
-	printf(_("  -q, --quiet              run quietly (no messages, only query output)\n"));
-	printf(_("  -s, --single-step        single-step mode (confirm each query)\n"));
-	printf(_("  -S, --single-line        single-line mode (end of line terminates SQL command)\n"));
-
-	printf(_("\nOutput format options:\n"));
-	printf(_("  -A, --no-align           unaligned table output mode\n"));
-	printf(_("  -F, --field-separator=STRING\n"
+	fprintf(output, _("  -?, --help               show this help, then exit\n"));
+	fprintf(output, _("  --help=variables         show a list of all specially treated variables, then exit\n"));
+
+	fprintf(output, _("\nInput and output options:\n"));
+	fprintf(output, _("  -a, --echo-all           echo all input from script\n"));
+	fprintf(output, _("  -b, --echo-errors        echo failed commands\n"));
+	fprintf(output, _("  -e, --echo-queries       echo commands sent to server\n"));
+	fprintf(output, _("  -E, --echo-hidden        display queries that internal commands generate\n"));
+	fprintf(output, _("  -L, --log-file=FILENAME  send session log to file\n"));
+	fprintf(output, _("  -n, --no-readline        disable enhanced command line editing (readline)\n"));
+	fprintf(output, _("  -o, --output=FILENAME    send query results to file (or |pipe)\n"));
+	fprintf(output, _("  -q, --quiet              run quietly (no messages, only query output)\n"));
+	fprintf(output, _("  -s, --single-step        single-step mode (confirm each query)\n"));
+	fprintf(output, _("  -S, --single-line        single-line mode (end of line terminates SQL command)\n"));
+
+	fprintf(output, _("\nOutput format options:\n"));
+	fprintf(output, _("  -A, --no-align           unaligned table output mode\n"));
+	fprintf(output, _("  -F, --field-separator=STRING\n"
 			 "                           field separator for unaligned output (default: \"%s\")\n"),
 		   DEFAULT_FIELD_SEP);
-	printf(_("  -H, --html               HTML table output mode\n"));
-	printf(_("  -P, --pset=VAR[=ARG]     set printing option VAR to ARG (see \\pset command)\n"));
-	printf(_("  -R, --record-separator=STRING\n"
+	fprintf(output, _("  -H, --html               HTML table output mode\n"));
+	fprintf(output, _("  -P, --pset=VAR[=ARG]     set printing option VAR to ARG (see \\pset command)\n"));
+	fprintf(output, _("  -R, --record-separator=STRING\n"
 			 "                           record separator for unaligned output (default: newline)\n"));
-	printf(_("  -t, --tuples-only        print rows only\n"));
-	printf(_("  -T, --table-attr=TEXT    set HTML table tag attributes (e.g., width, border)\n"));
-	printf(_("  -x, --expanded           turn on expanded table output\n"));
-	printf(_("  -z, --field-separator-zero\n"
+	fprintf(output, _("  -t, --tuples-only        print rows only\n"));
+	fprintf(output, _("  -T, --table-attr=TEXT    set HTML table tag attributes (e.g., width, border)\n"));
+	fprintf(output, _("  -x, --expanded           turn on expanded table output\n"));
+	fprintf(output, _("  -z, --field-separator-zero\n"
 			 "                           set field separator for unaligned output to zero byte\n"));
-	printf(_("  -0, --record-separator-zero\n"
+	fprintf(output, _("  -0, --record-separator-zero\n"
 			 "                           set record separator for unaligned output to zero byte\n"));
 
-	printf(_("\nConnection options:\n"));
+	fprintf(output, _("\nConnection options:\n"));
 	/* Display default host */
 	env = getenv("PGHOST");
-	printf(_("  -h, --host=HOSTNAME      database server host or socket directory (default: \"%s\")\n"),
+	fprintf(output, _("  -h, --host=HOSTNAME      database server host or socket directory (default: \"%s\")\n"),
 		   env ? env : _("local socket"));
 	/* Display default port */
 	env = getenv("PGPORT");
-	printf(_("  -p, --port=PORT          database server port (default: \"%s\")\n"),
+	fprintf(output, _("  -p, --port=PORT          database server port (default: \"%s\")\n"),
 		   env ? env : DEF_PGPORT_STR);
 	/* Display default user */
 	env = getenv("PGUSER");
 	if (!env)
 		env = user;
-	printf(_("  -U, --username=USERNAME  database user name (default: \"%s\")\n"), env);
-	printf(_("  -w, --no-password        never prompt for password\n"));
-	printf(_("  -W, --password           force password prompt (should happen automatically)\n"));
+	fprintf(output, _("  -U, --username=USERNAME  database user name (default: \"%s\")\n"), env);
+	fprintf(output, _("  -w, --no-password        never prompt for password\n"));
+	fprintf(output, _("  -W, --password           force password prompt (should happen automatically)\n"));
 
-	printf(_("\nFor more information, type \"\\?\" (for internal commands) or \"\\help\" (for SQL\n"
+	fprintf(output, _("\nFor more information, type \"\\?\" (for internal commands) or \"\\help\" (for SQL\n"
 			 "commands) from within psql, or consult the psql section in the PostgreSQL\n"
 			 "documentation.\n\n"));
-	printf(_("Report bugs to <pgsql-bugs@postgresql.org>.\n"));
+	fprintf(output, _("Report bugs to <pgsql-bugs@postgresql.org>.\n"));
+
+	ClosePager(output);
 }
 
 
@@ -159,11 +165,18 @@ slashUsage(unsigned short int pager)
 	fprintf(output, _("  \\copyright             show PostgreSQL usage and distribution terms\n"));
 	fprintf(output, _("  \\g [FILE] or ;         execute query (and send results to file or |pipe)\n"));
 	fprintf(output, _("  \\gset [PREFIX]         execute query and store results in psql variables\n"));
-	fprintf(output, _("  \\h [NAME]              help on syntax of SQL commands, * for all commands\n"));
 	fprintf(output, _("  \\q                     quit psql\n"));
 	fprintf(output, _("  \\watch [SEC]           execute query every SEC seconds\n"));
 	fprintf(output, "\n");
 
+	fprintf(output, _("Help\n"));
+
+	fprintf(output, _("  \\?                     description of all psql commands\n"));
+	fprintf(output, _("  \\? options             description of psql options\n"));
+	fprintf(output, _("  \\? variables           description of all psql configuration variables\n"));
+	fprintf(output, _("  \\h [NAME]              help on syntax of SQL commands, * for all commands\n"));
+	fprintf(output, "\n");
+
 	fprintf(output, _("Query Buffer\n"));
 	fprintf(output, _("  \\e [FILE] [LINE]       edit the query buffer (or file) with external editor\n"));
 	fprintf(output, _("  \\ef [FUNCNAME [LINE]]  edit function definition with external editor\n"));
@@ -280,6 +293,108 @@ slashUsage(unsigned short int pager)
 }
 
 
+/*
+ * show list of available variables (options) from command line
+ */
+void
+help_variables(unsigned short int pager)
+{
+	FILE	   *output;
+
+	output = PageOutput(86, pager);
+
+	fprintf(output, _("List of specially treated variables.\n"));
+
+	fprintf(output, _("psql variables:\n"));
+	fprintf(output, _("Usage:\n"));
+	fprintf(output, _("  psql --set=NAME=VALUE\n  or \\set NAME VALUE in interactive mode\n\n"));
+
+	fprintf(output, _("  AUTOCOMMIT         if set, successful SQL commands are automatically committed\n"));
+	fprintf(output, _("  COMP_KEYWORD_CASE  determine the case used to complete SQL keywords\n"
+					 "                     [lower, upper, preserve-lower, preserve-upper]\n"));
+	fprintf(output, _("  DBNAME             the currently connected database name\n"));
+	fprintf(output, _("  ECHO               control what input is written to standard output\n"
+					 "                     [all, errors, none, queries]\n"));
+	fprintf(output, _("  ECHO_HIDDEN        display internal queries executed by backslash commands when it is set\n"
+					 "                     or with [noexec] just show without execution\n"));
+	fprintf(output, _("  ENCODING           current client character set encoding\n"));
+	fprintf(output, _("  FETCH_COUNT        the number of result rows to fetch and display at a time\n"
+					 "                     (default: 0=unlimited)\n"));
+	fprintf(output, _("  HISTCONTROL        control history list [ignorespace, ignoredups, ignoreboth]\n"));
+	fprintf(output, _("  HISTFILE           file name used to store the history list\n"));
+	fprintf(output, _("  HISTSIZE           the number of commands to store in the command history\n"));
+	fprintf(output, _("  HOST               the currently connected database server\n"));
+	fprintf(output, _("  IGNOREEOF          if unset, sending an EOF to interactive session terminates application\n"));
+	fprintf(output, _("  LASTOID            the value of last affected OID\n"));
+	fprintf(output, _("  ON_ERROR_ROLLBACK  if set, an error doesn't stop a transaction (uses implicit SAVEPOINTs)\n"));
+	fprintf(output, _("  ON_ERROR_STOP      stop batch execution after error\n"));
+	fprintf(output, _("  PORT               server port of the current connection\n"));
+	fprintf(output, _("  PROMPT1            specify standard the psql prompt\n"));
+	fprintf(output, _("  PROMPT2            specify the psql prompt when statement continues from previous line\n"));
+	fprintf(output, _("  PROMPT3            specify the psql prompt used by COPY statement\n"));
+	fprintf(output, _("  QUIET              run quietly (same as -q option)\n"));
+	fprintf(output, _("  SINGLELINE         end of line terminates SQL command mode (same as -S option)\n"));
+	fprintf(output, _("  SINGLESTEP         single-step mode (same as -s option)\n"));
+	fprintf(output, _("  USER               the currently connected database user\n"));
+	fprintf(output, _("  VERBOSITY          control verbosity of error reports [default, verbose, terse]\n"));
+
+	fprintf(output, _("\nPrinting options:\n"));
+	fprintf(output, _("Usage:\n"));
+	fprintf(output, _("  psql --pset=NAME[=VALUE]\n  or \\pset NAME [VALUE] in interactive mode\n\n"));
+
+	fprintf(output, _("  border             border style (number)\n"));
+	fprintf(output, _("  columns            set the target width for the wrapped format\n"));
+	fprintf(output, _("  expanded (or x)    toggle expanded output\n"));
+	fprintf(output, _("  fieldsep           field separator for unaligned output (default '|')\n"));
+	fprintf(output, _("  fieldsep_zero      set field separator in unaligned mode to zero\n"));
+	fprintf(output, _("  format             set output format [unaligned, aligned, wrapped, html, latex, ..]\n"));
+	fprintf(output, _("  footer             enable or disable display of the table footer [on, off]\n"));
+	fprintf(output, _("  linestyle          set the border line drawing style [ascii, old-ascii, unicode]\n"));
+	fprintf(output, _("  null               set the string to be printed in place of a null value\n"));
+	fprintf(output, _("  numericlocale      enable or disable display of a locale-specific character to separate\n"
+					 "                     groups of digits [on, off]\n"));
+	fprintf(output, _("  pager              control when an external pager is used [yes, no, always]\n"));
+	fprintf(output, _("  recordsep          specify the record (line) separator to use in unaligned output format\n"));
+	fprintf(output, _("  recordsep_zero     set the record separator to use in unaligned output format to a zero byte.\n"));
+	fprintf(output, _("  tableattr (or T)   specify attributes for table tag in html format or proportional\n"
+					 "                     column width of left aligned data type in latex format\n"));
+	fprintf(output, _("  title              set the table title for any subsequently printed tables\n"));
+	fprintf(output, _("  tuples_only        if set, only actual table data is shown\n"));
+
+	fprintf(output, _("\nEnvironment variables:\n"));
+	fprintf(output, _("Usage:\n"));
+
+#ifndef WIN32
+	fprintf(output, _("  NAME=VALUE [NAME=VALUE] psql ...\n  or \\setenv NAME [VALUE] in interactive mode\n\n"));
+#else
+	fprintf(output, _("  set NAME=VALUE\n  psql ...\n  or \\setenv NAME VALUE in interactive mode\n\n"));
+#endif
+
+	fprintf(output, _("  COLUMNS            number of columns for wrapped format\n"));
+	fprintf(output, _("  PAGER              name of external pager program\n"));
+	fprintf(output, _("  PGAPPNAME          same as the application_name connection parameter\n"));
+	fprintf(output, _("  PGDATABASE         same as the dbname connection parameter\n"));
+	fprintf(output, _("  PGHOST             same as the host connection parameter\n"));
+	fprintf(output, _("  PGPORT             same as the port connection parameter\n"));
+	fprintf(output, _("  PGUSER             same as the user connection parameter\n"));
+	fprintf(output, _("  PGPASSWORD         connection password (not recommended)\n"));
+	fprintf(output, _("  PGPASSFILE         password file name\n"));
+	fprintf(output, _("  PSQL_EDITOR, EDITOR, VISUAL\n"
+					 "                     editor used by the \\e and \\ef commands\n"));
+	fprintf(output, _("  PSQL_EDITOR_LINENUMBER_ARG\n"
+					 "                     how to specify a line number when invoking the editor\n"));
+	fprintf(output, _("  PSQL_HISTORY       alternative location for the command history file\n"));
+	fprintf(output, _("  PSQLRC             alternative location for the user's .psqlrc file\n"));
+	fprintf(output, _("  SHELL              shell used by the \\! command\n"));
+	fprintf(output, _("  TMPDIR             directory for temporary files\n"));
+
+	fprintf(output, _("\nFor more information consult the psql section in the PostgreSQL\n"
+			 "documentation.\n\n"));
+	fprintf(output, _("Report bugs to <pgsql-bugs@postgresql.org>.\n"));
+
+	ClosePager(output);
+}
+
 
 /*
  * helpSQL -- help with SQL commands
diff --git a/src/bin/psql/help.h b/src/bin/psql/help.h
index 054d5a4..bab360d 100644
--- a/src/bin/psql/help.h
+++ b/src/bin/psql/help.h
@@ -8,10 +8,12 @@
 #ifndef HELP_H
 #define HELP_H
 
-void		usage(void);
+void		usage(unsigned short int pager);
 
 void		slashUsage(unsigned short int pager);
 
+void		help_variables(unsigned short int pager);
+
 void		helpSQL(const char *topic, unsigned short int pager);
 
 void		print_copyright(void);
diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c
index 5a397e8..dd051e6 100644
--- a/src/bin/psql/startup.c
+++ b/src/bin/psql/startup.c
@@ -77,6 +77,8 @@ static void process_psqlrc_file(char *filename);
 static void showVersion(void);
 static void EstablishVariableSpace(void);
 
+#define NOPAGER		0
+
 /*
  *
  * main
@@ -95,9 +97,9 @@ main(int argc, char *argv[])
 
 	if (argc > 1)
 	{
-		if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
+		if ((strcmp(argv[1], "-?") == 0) || (argc == 2 && (strcmp(argv[1], "--help") == 0)))
 		{
-			usage();
+			usage(NOPAGER);
 			exit(EXIT_SUCCESS);
 		}
 		if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
@@ -383,7 +385,7 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
 		{"password", no_argument, NULL, 'W'},
 		{"expanded", no_argument, NULL, 'x'},
 		{"no-psqlrc", no_argument, NULL, 'X'},
-		{"help", no_argument, NULL, '?'},
+		{"help", optional_argument, NULL, 1},
 		{NULL, 0, NULL, 0}
 	};
 
@@ -392,7 +394,7 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
 
 	memset(options, 0, sizeof *options);
 
-	while ((c = getopt_long(argc, argv, "aAbc:d:eEf:F:h:HlL:no:p:P:qR:sStT:U:v:VwWxXz?01",
+	while ((c = getopt_long(argc, argv, "aAbc:d:eEf:F:h:HlL:no:p:P:qR:sStT:U:v:VwWxXz?0",
 							long_options, &optindex)) != -1)
 	{
 		switch (c)
@@ -556,13 +558,11 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
 				options->single_txn = true;
 				break;
 			case '?':
-				/* Actual help option given */
-				if (strcmp(argv[optind - 1], "--help") == 0 || strcmp(argv[optind - 1], "-?") == 0)
+				if (strcmp(argv[optind - 1], "-?") == 0)
 				{
-					usage();
+					usage(NOPAGER);
 					exit(EXIT_SUCCESS);
 				}
-				/* unknown option reported by getopt */
 				else
 				{
 					fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
@@ -570,6 +570,16 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
 					exit(EXIT_FAILURE);
 				}
 				break;
+			case 1:
+				{
+					if (optarg && strcmp(optarg, "variables") == 0)
+						help_variables(NOPAGER);
+					else
+						usage(NOPAGER);
+
+					exit(EXIT_SUCCESS);
+				}
+				break;
 			default:
 				fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
 						pset.progname);
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 8288b41..ec6182b 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -3524,6 +3524,13 @@ psql_completion(const char *text, int start, int end)
 
 /* Backslash commands */
 /* TODO:  \dc \dd \dl */
+	else if (strcmp(prev_wd, "\\?") == 0)
+	{
+		static const char *const my_list[] =
+		{"options", "variables", NULL};
+
+		COMPLETE_WITH_LIST_CS(my_list);
+	}
 	else if (strcmp(prev_wd, "\\connect") == 0 || strcmp(prev_wd, "\\c") == 0)
 		COMPLETE_WITH_QUERY(Query_for_list_of_databases);
 
#40Andres Freund
andres@2ndquadrant.com
In reply to: Andres Freund (#30)

On 2014-08-28 13:54:28 +0200, Andres Freund wrote:

On 2014-08-28 13:20:07 +0200, Andres Freund wrote:

I've attached a incremental patch.

Apparently I didn't attach the patch, as so much a file containing the
name of the patchfile...

Which you obviously didn't integrate. And didn't comment on. Grr.

Greetings,

Andres Freund

--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#41Andres Freund
andres@2ndquadrant.com
In reply to: Andres Freund (#28)
2 attachment(s)

Hi,

Given we already have three topics for --help and I can see others I
went with my --help= proposal.

On 2014-08-28 13:20:07 +0200, Andres Freund wrote:

Some stuff I changed:
* I rephrased the sgml changes
* s/Printing options/Display options/. Or maybe "Display influencing
variables"? That makes it clearer why they're listed under
--help-variables.
* I added \? commands as an alias for a plain \?
That way the scheme can sensibly be expanded.
* I renamed help_variables() to be inline with the surrounding functions.

I integrated all those ontop of your help-variables-12.patch.

Then I:
* re-added psql -i which you, probably accidentally, removed
* rephrased the sgml stuff
* removed the "Report bugs to " from helpVariables()
* Changed things so that both --help and \? support "commands",
"options" and "variables" as help topics
* fixed things so that --help=wrongoption returns a proper exit code
again

I attached both the full and the incremental diff. I'd appreciate
somebody looking over the the docs...

I plan to push this soon.

Greetings,

Andres Freund

--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

Attachments:

help-variables-13.patchtext/x-patch; charset=us-asciiDownload
>From 9fcf3f0983ccd617c20dc4e87889a894d873b92e Mon Sep 17 00:00:00 2001
From: Andres Freund <andres@anarazel.de>
Date: Tue, 9 Sep 2014 22:19:14 +0200
Subject: [PATCH] Add new psql help topics, accessible to both --help and \?.

Add --help=<topic> for the commandline, and \? <topic> as a backslash
command, to show more help than the invocations without parameters
do. "commands", "variables" and "options" currently exist as help
topics describing, respectively, backslash commands, psql variables,
and commandline switches. Without parameters the help commands show
their previous topic.

Author: Pavel Stehule, editorialized by many

Reviewed-By: Andres Freund, Petr Jelinek, Fujii Masao, MauMau, Abhijit
    Menon-Sen and Erik Rijkers.

Discussion: CAFj8pRDVGuC-nXBfe2CK8vpyzd2Dsr9GVpbrATAnZO=2YQ0s2Q@mail.gmail.com,
    CAFj8pRA54AbTv2RXDTRxiAd8hy8wxmoVLqhJDRCwEnhdd7OUkw@mail.gmail.com
---
 doc/src/sgml/ref/psql-ref.sgml |  23 ++++-
 src/bin/psql/command.c         |  14 ++-
 src/bin/psql/help.c            | 210 +++++++++++++++++++++++++++++++----------
 src/bin/psql/help.h            |   4 +-
 src/bin/psql/startup.c         |  29 ++++--
 src/bin/psql/tab-complete.c    |   7 ++
 6 files changed, 224 insertions(+), 63 deletions(-)

diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index 29ad1aa..aa71674 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -560,11 +560,17 @@ EOF
 
     <varlistentry>
       <term><option>-?</></term>
-      <term><option>--help</></term>
+      <term><option>--help[=<replaceable class="parameter">topic</>]</option></term>
       <listitem>
       <para>
-      Show help about <application>psql</application> command line
-      arguments, and exit.
+      Show help about <application>psql</application> and exit. The optional
+      <replaceable class="parameter">topic</> parameter (defaulting
+      to <literal>options</literal>) selects which part of psql is
+      explained: <literal>commands</> describes <application>psql</>'s
+      backslash commands; <literal>options</> describes the commandline
+      switches that can be passed to <application>psql</>;
+      and <literal>variables</> shows help about about psql configuration
+      variables.
       </para>
       </listitem>
     </varlistentry>
@@ -2574,10 +2580,17 @@ testdb=&gt; <userinput>\setenv LESS -imx4F</userinput>
 
 
       <varlistentry>
-        <term><literal>\?</literal></term>
+        <term><literal>\? [ <replaceable class="parameter">topic</> ]</literal></term>
         <listitem>
         <para>
-        Shows help information about the backslash commands.
+        Shows help information. The optional
+        <replaceable class="parameter">topic</> parameter
+        (defaulting to <literal>commands</>) selects which part of psql is
+        explained: <literal>commands</> describes <application>psql</>'s
+        backslash commands; <literal>options</> describes the commandline
+        switches that can be passed to <application>psql</>;
+        and <literal>variables</> shows help about about psql configuration
+        variables.
         </para>
         </listitem>
       </varlistentry>
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index 39b5777..5d90ca2 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -1491,7 +1491,19 @@ exec_command(const char *cmd,
 
 	/* \? -- slash command help */
 	else if (strcmp(cmd, "?") == 0)
-		slashUsage(pset.popt.topt.pager);
+	{
+		char	   *opt0 = psql_scan_slash_option(scan_state,
+													OT_NORMAL, NULL, false);
+
+		if (!opt0 || strcmp(opt0, "commands") == 0)
+			slashUsage(pset.popt.topt.pager);
+		else if (strcmp(opt0, "options") == 0)
+			usage(pset.popt.topt.pager);
+		else if (strcmp(opt0, "variables") == 0)
+			helpVariables(pset.popt.topt.pager);
+		else
+			slashUsage(pset.popt.topt.pager);
+	}
 
 #if 0
 
diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c
index f8f000f..ef35696 100644
--- a/src/bin/psql/help.c
+++ b/src/bin/psql/help.c
@@ -46,11 +46,12 @@
 #define ON(var) (var ? _("on") : _("off"))
 
 void
-usage(void)
+usage(unsigned short int pager)
 {
 	const char *env;
 	const char *user;
 	char	   *errstr;
+	FILE	   *output;
 
 	/* Find default user, in case we need it. */
 	user = getenv("PGUSER");
@@ -64,77 +65,83 @@ usage(void)
 		}
 	}
 
-	printf(_("psql is the PostgreSQL interactive terminal.\n\n"));
-	printf(_("Usage:\n"));
-	printf(_("  psql [OPTION]... [DBNAME [USERNAME]]\n\n"));
+	output = PageOutput(59, pager);
+
+	fprintf(output, _("psql is the PostgreSQL interactive terminal.\n\n"));
+	fprintf(output, _("Usage:\n"));
+	fprintf(output, _("  psql [OPTION]... [DBNAME [USERNAME]]\n\n"));
 
-	printf(_("General options:\n"));
+	fprintf(output, _("General options:\n"));
 	/* Display default database */
 	env = getenv("PGDATABASE");
 	if (!env)
 		env = user;
-	printf(_("  -c, --command=COMMAND    run only single command (SQL or internal) and exit\n"));
-	printf(_("  -d, --dbname=DBNAME      database name to connect to (default: \"%s\")\n"), env);
-	printf(_("  -f, --file=FILENAME      execute commands from file, then exit\n"));
-	printf(_("  -l, --list               list available databases, then exit\n"));
-	printf(_("  -v, --set=, --variable=NAME=VALUE\n"
-			 "                           set psql variable NAME to VALUE\n"));
-	printf(_("  -V, --version            output version information, then exit\n"));
-	printf(_("  -X, --no-psqlrc          do not read startup file (~/.psqlrc)\n"));
-	printf(_("  -1 (\"one\"), --single-transaction\n"
+	fprintf(output, _("  -c, --command=COMMAND    run only single command (SQL or internal) and exit\n"));
+	fprintf(output, _("  -d, --dbname=DBNAME      database name to connect to (default: \"%s\")\n"), env);
+	fprintf(output, _("  -f, --file=FILENAME      execute commands from file, then exit\n"));
+	fprintf(output, _("  -l, --list               list available databases, then exit\n"));
+	fprintf(output, _("  -v, --set=, --variable=NAME=VALUE\n"
+			 "                           set psql variable NAME to VALUE e.g.: -v ON_ERROR_STOP=1\n"));
+	fprintf(output, _("  -V, --version            output version information, then exit\n"));
+	fprintf(output, _("  -X, --no-psqlrc          do not read startup file (~/.psqlrc)\n"));
+	fprintf(output, _("  -1 (\"one\"), --single-transaction\n"
 			 "                           execute as a single transaction (if non-interactive)\n"));
-	printf(_("  -?, --help               show this help, then exit\n"));
-
-	printf(_("\nInput and output options:\n"));
-	printf(_("  -a, --echo-all           echo all input from script\n"));
-	printf(_("  -b, --echo-errors        echo failed commands\n"));
-	printf(_("  -e, --echo-queries       echo commands sent to server\n"));
-	printf(_("  -E, --echo-hidden        display queries that internal commands generate\n"));
-	printf(_("  -L, --log-file=FILENAME  send session log to file\n"));
-	printf(_("  -n, --no-readline        disable enhanced command line editing (readline)\n"));
-	printf(_("  -o, --output=FILENAME    send query results to file (or |pipe)\n"));
-	printf(_("  -q, --quiet              run quietly (no messages, only query output)\n"));
-	printf(_("  -s, --single-step        single-step mode (confirm each query)\n"));
-	printf(_("  -S, --single-line        single-line mode (end of line terminates SQL command)\n"));
-
-	printf(_("\nOutput format options:\n"));
-	printf(_("  -A, --no-align           unaligned table output mode\n"));
-	printf(_("  -F, --field-separator=STRING\n"
+	fprintf(output, _("  -?, --help[=options]     show this help, then exit\n"));
+	fprintf(output, _("      --help=variables     show a list of all specially treated variables, then exit\n"));
+	fprintf(output, _("      --help=commands      show a list of backslash commands, then exit\n"));
+
+	fprintf(output, _("\nInput and output options:\n"));
+	fprintf(output, _("  -a, --echo-all           echo all input from script\n"));
+	fprintf(output, _("  -b, --echo-errors        echo failed commands\n"));
+	fprintf(output, _("  -e, --echo-queries       echo commands sent to server\n"));
+	fprintf(output, _("  -E, --echo-hidden        display queries that internal commands generate\n"));
+	fprintf(output, _("  -L, --log-file=FILENAME  send session log to file\n"));
+	fprintf(output, _("  -n, --no-readline        disable enhanced command line editing (readline)\n"));
+	fprintf(output, _("  -o, --output=FILENAME    send query results to file (or |pipe)\n"));
+	fprintf(output, _("  -q, --quiet              run quietly (no messages, only query output)\n"));
+	fprintf(output, _("  -s, --single-step        single-step mode (confirm each query)\n"));
+	fprintf(output, _("  -S, --single-line        single-line mode (end of line terminates SQL command)\n"));
+
+	fprintf(output, _("\nOutput format options:\n"));
+	fprintf(output, _("  -A, --no-align           unaligned table output mode\n"));
+	fprintf(output, _("  -F, --field-separator=STRING\n"
 			 "                           field separator for unaligned output (default: \"%s\")\n"),
 		   DEFAULT_FIELD_SEP);
-	printf(_("  -H, --html               HTML table output mode\n"));
-	printf(_("  -P, --pset=VAR[=ARG]     set printing option VAR to ARG (see \\pset command)\n"));
-	printf(_("  -R, --record-separator=STRING\n"
+	fprintf(output, _("  -H, --html               HTML table output mode\n"));
+	fprintf(output, _("  -P, --pset=VAR[=ARG]     set printing option VAR to ARG (see \\pset command)\n"));
+	fprintf(output, _("  -R, --record-separator=STRING\n"
 			 "                           record separator for unaligned output (default: newline)\n"));
-	printf(_("  -t, --tuples-only        print rows only\n"));
-	printf(_("  -T, --table-attr=TEXT    set HTML table tag attributes (e.g., width, border)\n"));
-	printf(_("  -x, --expanded           turn on expanded table output\n"));
-	printf(_("  -z, --field-separator-zero\n"
+	fprintf(output, _("  -t, --tuples-only        print rows only\n"));
+	fprintf(output, _("  -T, --table-attr=TEXT    set HTML table tag attributes (e.g., width, border)\n"));
+	fprintf(output, _("  -x, --expanded           turn on expanded table output\n"));
+	fprintf(output, _("  -z, --field-separator-zero\n"
 			 "                           set field separator for unaligned output to zero byte\n"));
-	printf(_("  -0, --record-separator-zero\n"
+	fprintf(output, _("  -0, --record-separator-zero\n"
 			 "                           set record separator for unaligned output to zero byte\n"));
 
-	printf(_("\nConnection options:\n"));
+	fprintf(output, _("\nConnection options:\n"));
 	/* Display default host */
 	env = getenv("PGHOST");
-	printf(_("  -h, --host=HOSTNAME      database server host or socket directory (default: \"%s\")\n"),
+	fprintf(output, _("  -h, --host=HOSTNAME      database server host or socket directory (default: \"%s\")\n"),
 		   env ? env : _("local socket"));
 	/* Display default port */
 	env = getenv("PGPORT");
-	printf(_("  -p, --port=PORT          database server port (default: \"%s\")\n"),
+	fprintf(output, _("  -p, --port=PORT          database server port (default: \"%s\")\n"),
 		   env ? env : DEF_PGPORT_STR);
 	/* Display default user */
 	env = getenv("PGUSER");
 	if (!env)
 		env = user;
-	printf(_("  -U, --username=USERNAME  database user name (default: \"%s\")\n"), env);
-	printf(_("  -w, --no-password        never prompt for password\n"));
-	printf(_("  -W, --password           force password prompt (should happen automatically)\n"));
+	fprintf(output, _("  -U, --username=USERNAME  database user name (default: \"%s\")\n"), env);
+	fprintf(output, _("  -w, --no-password        never prompt for password\n"));
+	fprintf(output, _("  -W, --password           force password prompt (should happen automatically)\n"));
 
-	printf(_("\nFor more information, type \"\\?\" (for internal commands) or \"\\help\" (for SQL\n"
+	fprintf(output, _("\nFor more information, type \"\\?\" (for internal commands) or \"\\help\" (for SQL\n"
 			 "commands) from within psql, or consult the psql section in the PostgreSQL\n"
 			 "documentation.\n\n"));
-	printf(_("Report bugs to <pgsql-bugs@postgresql.org>.\n"));
+	fprintf(output, _("Report bugs to <pgsql-bugs@postgresql.org>.\n"));
+
+	ClosePager(output);
 }
 
 
@@ -159,11 +166,18 @@ slashUsage(unsigned short int pager)
 	fprintf(output, _("  \\copyright             show PostgreSQL usage and distribution terms\n"));
 	fprintf(output, _("  \\g [FILE] or ;         execute query (and send results to file or |pipe)\n"));
 	fprintf(output, _("  \\gset [PREFIX]         execute query and store results in psql variables\n"));
-	fprintf(output, _("  \\h [NAME]              help on syntax of SQL commands, * for all commands\n"));
 	fprintf(output, _("  \\q                     quit psql\n"));
 	fprintf(output, _("  \\watch [SEC]           execute query every SEC seconds\n"));
 	fprintf(output, "\n");
 
+	fprintf(output, _("Help\n"));
+
+	fprintf(output, _("  \\? [commands]          description of all psql backslash commands\n"));
+	fprintf(output, _("  \\? options             description of all psql commandline options\n"));
+	fprintf(output, _("  \\? variables           description of all psql configuration variables\n"));
+	fprintf(output, _("  \\h [NAME]              help on syntax of SQL commands, * for all commands\n"));
+	fprintf(output, "\n");
+
 	fprintf(output, _("Query Buffer\n"));
 	fprintf(output, _("  \\e [FILE] [LINE]       edit the query buffer (or file) with external editor\n"));
 	fprintf(output, _("  \\ef [FUNCNAME [LINE]]  edit function definition with external editor\n"));
@@ -280,6 +294,106 @@ slashUsage(unsigned short int pager)
 }
 
 
+/*
+ * helpVariables
+ *
+ * show list of available variables (options) from command line
+ */
+void
+helpVariables(unsigned short int pager)
+{
+	FILE	   *output;
+
+	output = PageOutput(81, pager);
+
+	fprintf(output, _("List of specially treated variables.\n"));
+
+	fprintf(output, _("psql variables:\n"));
+	fprintf(output, _("Usage:\n"));
+	fprintf(output, _("  psql --set=NAME=VALUE\n  or \\set NAME VALUE in interactive mode\n\n"));
+
+	fprintf(output, _("  AUTOCOMMIT         if set, successful SQL commands are automatically committed\n"));
+	fprintf(output, _("  COMP_KEYWORD_CASE  determine the case used to complete SQL keywords\n"
+					 "                     [lower, upper, preserve-lower, preserve-upper]\n"));
+	fprintf(output, _("  DBNAME             the currently connected database name\n"));
+	fprintf(output, _("  ECHO               control what input is written to standard output\n"
+					 "                     [all, errors, none, queries]\n"));
+	fprintf(output, _("  ECHO_HIDDEN        display internal queries executed by backslash commands when it is set\n"
+					 "                     or with [noexec] just show without execution\n"));
+	fprintf(output, _("  ENCODING           current client character set encoding\n"));
+	fprintf(output, _("  FETCH_COUNT        the number of result rows to fetch and display at a time\n"
+					 "                     (default: 0=unlimited)\n"));
+	fprintf(output, _("  HISTCONTROL        control history list [ignorespace, ignoredups, ignoreboth]\n"));
+	fprintf(output, _("  HISTFILE           file name used to store the history list\n"));
+	fprintf(output, _("  HISTSIZE           the number of commands to store in the command history\n"));
+	fprintf(output, _("  HOST               the currently connected database server\n"));
+	fprintf(output, _("  IGNOREEOF          if unset, sending an EOF to interactive session terminates application\n"));
+	fprintf(output, _("  LASTOID            the value of last affected OID\n"));
+	fprintf(output, _("  ON_ERROR_ROLLBACK  if set, an error doesn't stop a transaction (uses implicit SAVEPOINTs)\n"));
+	fprintf(output, _("  ON_ERROR_STOP      stop batch execution after error\n"));
+	fprintf(output, _("  PORT               server port of the current connection\n"));
+	fprintf(output, _("  PROMPT1            specify the standard psql prompt\n"));
+	fprintf(output, _("  PROMPT2            specify the prompt used when a statement continues from a previous line\n"));
+	fprintf(output, _("  PROMPT3            specify the prompt used during COPY ... FROM STDIN\n"));
+	fprintf(output, _("  QUIET              run quietly (same as -q option)\n"));
+	fprintf(output, _("  SINGLELINE         end of line terminates SQL command mode (same as -S option)\n"));
+	fprintf(output, _("  SINGLESTEP         single-step mode (same as -s option)\n"));
+	fprintf(output, _("  USER               the currently connected database user\n"));
+	fprintf(output, _("  VERBOSITY          control verbosity of error reports [default, verbose, terse]\n"));
+
+	fprintf(output, _("\nDisplay influencing variables:\n"));
+	fprintf(output, _("Usage:\n"));
+	fprintf(output, _("  psql --pset=NAME[=VALUE]\n  or \\pset NAME [VALUE] in interactive mode\n\n"));
+
+	fprintf(output, _("  border             border style (number)\n"));
+	fprintf(output, _("  columns            set the target width for the wrapped format\n"));
+	fprintf(output, _("  expanded (or x)    toggle expanded output\n"));
+	fprintf(output, _("  fieldsep           field separator for unaligned output (default '|')\n"));
+	fprintf(output, _("  fieldsep_zero      set field separator in unaligned mode to zero\n"));
+	fprintf(output, _("  format             set output format [unaligned, aligned, wrapped, html, latex, ..]\n"));
+	fprintf(output, _("  footer             enable or disable display of the table footer [on, off]\n"));
+	fprintf(output, _("  linestyle          set the border line drawing style [ascii, old-ascii, unicode]\n"));
+	fprintf(output, _("  null               set the string to be printed in place of a null value\n"));
+	fprintf(output, _("  numericlocale      enable or disable display of a locale-specific character to separate\n"
+					 "                     groups of digits [on, off]\n"));
+	fprintf(output, _("  pager              control when an external pager is used [yes, no, always]\n"));
+	fprintf(output, _("  recordsep          specify the record (line) separator to use in unaligned output format\n"));
+	fprintf(output, _("  recordsep_zero     set the record separator to use in unaligned output format to a zero byte.\n"));
+	fprintf(output, _("  tableattr (or T)   specify attributes for table tag in html format or proportional\n"
+					 "                     column width of left aligned data type in latex format\n"));
+	fprintf(output, _("  title              set the table title for any subsequently printed tables\n"));
+	fprintf(output, _("  tuples_only        if set, only actual table data is shown\n"));
+
+	fprintf(output, _("\nEnvironment variables:\n"));
+	fprintf(output, _("Usage:\n"));
+
+#ifndef WIN32
+	fprintf(output, _("  NAME=VALUE [NAME=VALUE] psql ...\n  or \\setenv NAME [VALUE] in interactive mode\n\n"));
+#else
+	fprintf(output, _("  set NAME=VALUE\n  psql ...\n  or \\setenv NAME VALUE in interactive mode\n\n"));
+#endif
+
+	fprintf(output, _("  COLUMNS            number of columns for wrapped format\n"));
+	fprintf(output, _("  PAGER              name of external pager program\n"));
+	fprintf(output, _("  PGAPPNAME          same as the application_name connection parameter\n"));
+	fprintf(output, _("  PGDATABASE         same as the dbname connection parameter\n"));
+	fprintf(output, _("  PGHOST             same as the host connection parameter\n"));
+	fprintf(output, _("  PGPORT             same as the port connection parameter\n"));
+	fprintf(output, _("  PGUSER             same as the user connection parameter\n"));
+	fprintf(output, _("  PGPASSWORD         connection password (not recommended)\n"));
+	fprintf(output, _("  PGPASSFILE         password file name\n"));
+	fprintf(output, _("  PSQL_EDITOR, EDITOR, VISUAL\n"
+					 "                     editor used by the \\e and \\ef commands\n"));
+	fprintf(output, _("  PSQL_EDITOR_LINENUMBER_ARG\n"
+					 "                     how to specify a line number when invoking the editor\n"));
+	fprintf(output, _("  PSQL_HISTORY       alternative location for the command history file\n"));
+	fprintf(output, _("  PSQLRC             alternative location for the user's .psqlrc file\n"));
+	fprintf(output, _("  SHELL              shell used by the \\! command\n"));
+	fprintf(output, _("  TMPDIR             directory for temporary files\n"));
+
+	ClosePager(output);
+}
+
 
 /*
  * helpSQL -- help with SQL commands
diff --git a/src/bin/psql/help.h b/src/bin/psql/help.h
index 054d5a4..3ad374a 100644
--- a/src/bin/psql/help.h
+++ b/src/bin/psql/help.h
@@ -8,10 +8,12 @@
 #ifndef HELP_H
 #define HELP_H
 
-void		usage(void);
+void		usage(unsigned short int pager);
 
 void		slashUsage(unsigned short int pager);
 
+void		helpVariables(unsigned short int pager);
+
 void		helpSQL(const char *topic, unsigned short int pager);
 
 void		print_copyright(void);
diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c
index 5a397e8..b879d0c 100644
--- a/src/bin/psql/startup.c
+++ b/src/bin/psql/startup.c
@@ -77,6 +77,8 @@ static void process_psqlrc_file(char *filename);
 static void showVersion(void);
 static void EstablishVariableSpace(void);
 
+#define NOPAGER		0
+
 /*
  *
  * main
@@ -95,9 +97,9 @@ main(int argc, char *argv[])
 
 	if (argc > 1)
 	{
-		if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
+		if ((strcmp(argv[1], "-?") == 0) || (argc == 2 && (strcmp(argv[1], "--help") == 0)))
 		{
-			usage();
+			usage(NOPAGER);
 			exit(EXIT_SUCCESS);
 		}
 		if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
@@ -383,7 +385,7 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
 		{"password", no_argument, NULL, 'W'},
 		{"expanded", no_argument, NULL, 'x'},
 		{"no-psqlrc", no_argument, NULL, 'X'},
-		{"help", no_argument, NULL, '?'},
+		{"help", optional_argument, NULL, 1},
 		{NULL, 0, NULL, 0}
 	};
 
@@ -557,20 +559,31 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
 				break;
 			case '?':
 				/* Actual help option given */
-				if (strcmp(argv[optind - 1], "--help") == 0 || strcmp(argv[optind - 1], "-?") == 0)
+				if (strcmp(argv[optind - 1], "-?") == 0)
 				{
-					usage();
+					usage(NOPAGER);
 					exit(EXIT_SUCCESS);
 				}
 				/* unknown option reported by getopt */
 				else
+					goto unknown_option;
+				break;
+			case 1:
 				{
-					fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
-							pset.progname);
-					exit(EXIT_FAILURE);
+					if (!optarg || strcmp(optarg, "options") == 0)
+						usage(NOPAGER);
+					else if (optarg && strcmp(optarg, "commands") == 0)
+						slashUsage(NOPAGER);
+					else if (optarg && strcmp(optarg, "variables") == 0)
+						helpVariables(NOPAGER);
+					else
+						goto unknown_option;
+
+					exit(EXIT_SUCCESS);
 				}
 				break;
 			default:
+			unknown_option:
 				fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
 						pset.progname);
 				exit(EXIT_FAILURE);
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 7577c4b..4ce47e9 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -3543,6 +3543,13 @@ psql_completion(const char *text, int start, int end)
 
 /* Backslash commands */
 /* TODO:  \dc \dd \dl */
+	else if (strcmp(prev_wd, "\\?") == 0)
+	{
+		static const char *const my_list[] =
+		{"commands", "options", "variables", NULL};
+
+		COMPLETE_WITH_LIST_CS(my_list);
+	}
 	else if (strcmp(prev_wd, "\\connect") == 0 || strcmp(prev_wd, "\\c") == 0)
 		COMPLETE_WITH_QUERY(Query_for_list_of_databases);
 
-- 
2.0.0.rc2.4.g1dc51c6.dirty

help-variables-12--13.difftext/x-diff; charset=us-asciiDownload
diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index c5b091c..aa71674 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -560,19 +560,18 @@ EOF
 
     <varlistentry>
       <term><option>-?</></term>
-      <term><option>--help</></term>
-      <term><option>--help=<replaceable class="parameter">topic</replaceable></option></term>
+      <term><option>--help[=<replaceable class="parameter">topic</>]</option></term>
       <listitem>
       <para>
-      Show help about <application>psql</application> command line
-      arguments, and exit.
+      Show help about <application>psql</application> and exit. The optional
+      <replaceable class="parameter">topic</> parameter (defaulting
+      to <literal>options</literal>) selects which part of psql is
+      explained: <literal>commands</> describes <application>psql</>'s
+      backslash commands; <literal>options</> describes the commandline
+      switches that can be passed to <application>psql</>;
+      and <literal>variables</> shows help about about psql configuration
+      variables.
       </para>
-
-      <para>
-      <option>--help=variables</>show help about <application>psql</application> variables,
-      and exit.
-      </para>
-
       </listitem>
     </varlistentry>
 
@@ -2581,12 +2580,17 @@ testdb=&gt; <userinput>\setenv LESS -imx4F</userinput>
 
 
       <varlistentry>
-        <term><literal>\? [ options | variables ]</literal></term>
+        <term><literal>\? [ <replaceable class="parameter">topic</> ]</literal></term>
         <listitem>
         <para>
-        Shows help information about the backslash commands.  This command can have a
-        option "variables" or "options" to take help for psql configuration variables
-        or psql command line options.
+        Shows help information. The optional
+        <replaceable class="parameter">topic</> parameter
+        (defaulting to <literal>commands</>) selects which part of psql is
+        explained: <literal>commands</> describes <application>psql</>'s
+        backslash commands; <literal>options</> describes the commandline
+        switches that can be passed to <application>psql</>;
+        and <literal>variables</> shows help about about psql configuration
+        variables.
         </para>
         </listitem>
       </varlistentry>
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index c7140b8..5d90ca2 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -1495,12 +1495,12 @@ exec_command(const char *cmd,
 		char	   *opt0 = psql_scan_slash_option(scan_state,
 													OT_NORMAL, NULL, false);
 
-		if (!opt0)
+		if (!opt0 || strcmp(opt0, "commands") == 0)
 			slashUsage(pset.popt.topt.pager);
-		else if (strcmp(opt0, "variables") == 0)
-			help_variables(pset.popt.topt.pager);
 		else if (strcmp(opt0, "options") == 0)
 			usage(pset.popt.topt.pager);
+		else if (strcmp(opt0, "variables") == 0)
+			helpVariables(pset.popt.topt.pager);
 		else
 			slashUsage(pset.popt.topt.pager);
 	}
diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c
index 0ada015..ef35696 100644
--- a/src/bin/psql/help.c
+++ b/src/bin/psql/help.c
@@ -86,8 +86,9 @@ usage(unsigned short int pager)
 	fprintf(output, _("  -X, --no-psqlrc          do not read startup file (~/.psqlrc)\n"));
 	fprintf(output, _("  -1 (\"one\"), --single-transaction\n"
 			 "                           execute as a single transaction (if non-interactive)\n"));
-	fprintf(output, _("  -?, --help               show this help, then exit\n"));
-	fprintf(output, _("  --help=variables         show a list of all specially treated variables, then exit\n"));
+	fprintf(output, _("  -?, --help[=options]     show this help, then exit\n"));
+	fprintf(output, _("      --help=variables     show a list of all specially treated variables, then exit\n"));
+	fprintf(output, _("      --help=commands      show a list of backslash commands, then exit\n"));
 
 	fprintf(output, _("\nInput and output options:\n"));
 	fprintf(output, _("  -a, --echo-all           echo all input from script\n"));
@@ -171,8 +172,8 @@ slashUsage(unsigned short int pager)
 
 	fprintf(output, _("Help\n"));
 
-	fprintf(output, _("  \\?                     description of all psql commands\n"));
-	fprintf(output, _("  \\? options             description of psql options\n"));
+	fprintf(output, _("  \\? [commands]          description of all psql backslash commands\n"));
+	fprintf(output, _("  \\? options             description of all psql commandline options\n"));
 	fprintf(output, _("  \\? variables           description of all psql configuration variables\n"));
 	fprintf(output, _("  \\h [NAME]              help on syntax of SQL commands, * for all commands\n"));
 	fprintf(output, "\n");
@@ -294,14 +295,16 @@ slashUsage(unsigned short int pager)
 
 
 /*
+ * helpVariables
+ *
  * show list of available variables (options) from command line
  */
 void
-help_variables(unsigned short int pager)
+helpVariables(unsigned short int pager)
 {
 	FILE	   *output;
 
-	output = PageOutput(86, pager);
+	output = PageOutput(81, pager);
 
 	fprintf(output, _("List of specially treated variables.\n"));
 
@@ -329,16 +332,16 @@ help_variables(unsigned short int pager)
 	fprintf(output, _("  ON_ERROR_ROLLBACK  if set, an error doesn't stop a transaction (uses implicit SAVEPOINTs)\n"));
 	fprintf(output, _("  ON_ERROR_STOP      stop batch execution after error\n"));
 	fprintf(output, _("  PORT               server port of the current connection\n"));
-	fprintf(output, _("  PROMPT1            specify standard the psql prompt\n"));
-	fprintf(output, _("  PROMPT2            specify the psql prompt when statement continues from previous line\n"));
-	fprintf(output, _("  PROMPT3            specify the psql prompt used by COPY statement\n"));
+	fprintf(output, _("  PROMPT1            specify the standard psql prompt\n"));
+	fprintf(output, _("  PROMPT2            specify the prompt used when a statement continues from a previous line\n"));
+	fprintf(output, _("  PROMPT3            specify the prompt used during COPY ... FROM STDIN\n"));
 	fprintf(output, _("  QUIET              run quietly (same as -q option)\n"));
 	fprintf(output, _("  SINGLELINE         end of line terminates SQL command mode (same as -S option)\n"));
 	fprintf(output, _("  SINGLESTEP         single-step mode (same as -s option)\n"));
 	fprintf(output, _("  USER               the currently connected database user\n"));
 	fprintf(output, _("  VERBOSITY          control verbosity of error reports [default, verbose, terse]\n"));
 
-	fprintf(output, _("\nPrinting options:\n"));
+	fprintf(output, _("\nDisplay influencing variables:\n"));
 	fprintf(output, _("Usage:\n"));
 	fprintf(output, _("  psql --pset=NAME[=VALUE]\n  or \\pset NAME [VALUE] in interactive mode\n\n"));
 
@@ -388,10 +391,6 @@ help_variables(unsigned short int pager)
 	fprintf(output, _("  SHELL              shell used by the \\! command\n"));
 	fprintf(output, _("  TMPDIR             directory for temporary files\n"));
 
-	fprintf(output, _("\nFor more information consult the psql section in the PostgreSQL\n"
-			 "documentation.\n\n"));
-	fprintf(output, _("Report bugs to <pgsql-bugs@postgresql.org>.\n"));
-
 	ClosePager(output);
 }
 
diff --git a/src/bin/psql/help.h b/src/bin/psql/help.h
index bab360d..3ad374a 100644
--- a/src/bin/psql/help.h
+++ b/src/bin/psql/help.h
@@ -12,7 +12,7 @@ void		usage(unsigned short int pager);
 
 void		slashUsage(unsigned short int pager);
 
-void		help_variables(unsigned short int pager);
+void		helpVariables(unsigned short int pager);
 
 void		helpSQL(const char *topic, unsigned short int pager);
 
diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c
index dd051e6..b879d0c 100644
--- a/src/bin/psql/startup.c
+++ b/src/bin/psql/startup.c
@@ -394,7 +394,7 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
 
 	memset(options, 0, sizeof *options);
 
-	while ((c = getopt_long(argc, argv, "aAbc:d:eEf:F:h:HlL:no:p:P:qR:sStT:U:v:VwWxXz?0",
+	while ((c = getopt_long(argc, argv, "aAbc:d:eEf:F:h:HlL:no:p:P:qR:sStT:U:v:VwWxXz?01",
 							long_options, &optindex)) != -1)
 	{
 		switch (c)
@@ -558,29 +558,32 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
 				options->single_txn = true;
 				break;
 			case '?':
+				/* Actual help option given */
 				if (strcmp(argv[optind - 1], "-?") == 0)
 				{
 					usage(NOPAGER);
 					exit(EXIT_SUCCESS);
 				}
+				/* unknown option reported by getopt */
 				else
-				{
-					fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
-							pset.progname);
-					exit(EXIT_FAILURE);
-				}
+					goto unknown_option;
 				break;
 			case 1:
 				{
-					if (optarg && strcmp(optarg, "variables") == 0)
-						help_variables(NOPAGER);
-					else
+					if (!optarg || strcmp(optarg, "options") == 0)
 						usage(NOPAGER);
+					else if (optarg && strcmp(optarg, "commands") == 0)
+						slashUsage(NOPAGER);
+					else if (optarg && strcmp(optarg, "variables") == 0)
+						helpVariables(NOPAGER);
+					else
+						goto unknown_option;
 
 					exit(EXIT_SUCCESS);
 				}
 				break;
 			default:
+			unknown_option:
 				fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
 						pset.progname);
 				exit(EXIT_FAILURE);
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 012f8c5..4ce47e9 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -3546,7 +3546,7 @@ psql_completion(const char *text, int start, int end)
 	else if (strcmp(prev_wd, "\\?") == 0)
 	{
 		static const char *const my_list[] =
-		{"options", "variables", NULL};
+		{"commands", "options", "variables", NULL};
 
 		COMPLETE_WITH_LIST_CS(my_list);
 	}
#42Andres Freund
andres@2ndquadrant.com
In reply to: Andres Freund (#41)

On 2014-09-09 22:22:45 +0200, Andres Freund wrote:

I plan to push this soon.

Done.

Thanks for the patch!

Andres Freund

--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#43Pavel Stehule
pavel.stehule@gmail.com
In reply to: Andres Freund (#42)

2014-09-10 0:13 GMT+02:00 Andres Freund <andres@2ndquadrant.com>:

On 2014-09-09 22:22:45 +0200, Andres Freund wrote:

I plan to push this soon.

Done.

Thanks for the patch!

Thank you very much

Pavel

Show quoted text

Andres Freund

--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services