Re: [HACKERS] psql and pset without any arguments

2013-09-02 Thread Gilles Darold
Patch added to current open commitfest under the Client section with title:

   Call \pset without any arguments displays current status of all
printing options

Status: Need review.

Let me know if it should not be there.

Regards,

Le 29/06/2013 01:08, Gilles Darold a écrit :
 Hi,

 I was looking at psql 8.3 documention about \pset options and saw that
 there was the following note :

 Note: It is an error to call \pset without any arguments. In the
 future this case might show the current status of all printing options.

 I looked backward and forward to find that this note is present in all
 versions since 7.1 up to 9.3, maybe it is time to add this little feature.

 I've attached a patch to add the usage of the \pset command without any
 arguments to displays current status of all printing options instead of
 the error message. Here is a sample output:

 (postgres@[local]:5494) [postgres]  \pset
 Output format is aligned.
 Border style is 2.
 Expanded display is used automatically.
 Null display is NULL.
 Field separator is |.
 Tuples only is off.
 Title is unset.
 Table attributes unset.
 Line style is unicode.
 Pager is used for long output.
 Record separator is newline.
 (postgres@[local]:5494) [postgres] 

 To avoid redundant code I've added a new method printPsetInfo() so that
 do_pset() and exec_command() will used the same output message, they are
 all in src/bin/psql/command.c. For example:

 (postgres@[local]:5494) [postgres]  \pset null 'NULL'
 Null display is NULL.
 (postgres@[local]:5494) [postgres] 

 The patch print all variables information from struct printTableOpt when
 \pset is given without any arguments and also update documentation.

 Let me know if there's any additional work to do on this basic patch or
 something that I've omitted.

 Best regards,

-- 
Gilles Darold
http://dalibo.com - http://dalibo.org



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


Re: [HACKERS] psql and pset without any arguments

2013-06-29 Thread Marc Mamin

Von: pgsql-hackers-ow...@postgresql.org 
[pgsql-hackers-ow...@postgresql.org]quot; im Auftrag von quot;Gilles Darold 
[gilles.dar...@dalibo.com]

I was looking at psql 8.3 documention about \pset options and saw that
there was the following note :

Note: It is an error to call \pset without any arguments. In the
future this case might show the current status of all printing options.

I looked backward and forward to find that this note is present in all
versions since 7.1 up to 9.3, maybe it is time to add this little feature.

I've attached a patch to add the usage of the \pset command without any
arguments to displays current status of all printing options instead of
the error message. Here is a sample output:

(postgres@[local]:5494) [postgres]  \pset
Output format is aligned.
Border style is 2.
Expanded display is used automatically.
Null display is NULL.
Field separator is |.
Tuples only is off.
Title is unset.
Table attributes unset.
Line style is unicode.
Pager is used for long output.
Record separator is newline.
(postgres@[local]:5494) [postgres] 


Hello,
this is a nice additional feature.
As a user (not a hacker), I would prefer to see the real parameter name instead 
of the display name.

e.g.
Border style is 2.
=
border = 2

without this, the user would not know out of the fly which parameter to 
modify...

best regards,
Marc Mamin

To avoid redundant code I've added a new method printPsetInfo() so that
do_pset() and exec_command() will used the same output message, they are
all in src/bin/psql/command.c. For example:

(postgres@[local]:5494) [postgres]  \pset null 'NULL'
Null display is NULL.
(postgres@[local]:5494) [postgres] 

The patch print all variables information from struct printTableOpt when
\pset is given without any arguments and also update documentation.

Let me know if there's any additional work to do on this basic patch or
something that I've omitted.

Best regards,

--
Gilles Darold
http://dalibo.com - http://dalibo.org


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


Re: [HACKERS] psql and pset without any arguments

2013-06-29 Thread Erik Rijkers
On Sat, June 29, 2013 01:08, Gilles Darold wrote:
  Here is a sample output:

 (postgres@[local]:5494) [postgres]  \pset
 Output format is aligned.
 Border style is 2.
 Expanded display is used automatically.
 Null display is NULL.
 Field separator is |.
 Tuples only is off.
 Title is unset.
 Table attributes unset.
 Line style is unicode.
 Pager is used for long output.
 Record separator is newline.
 (postgres@[local]:5494) [postgres] 


+1

This seems handy.  Maybe it could be improved
a bit with the keyboard shortcuts prefixed, like so:

(postgres@[local]:5494) [postgres]  \pset
\a  Output format is aligned.
\x  Expanded display is used automatically.
\f  Field separator is |.
\t  Tuples only is off.
\C  Title is unset.
\T  Table attributes unset.
Border style is 2.
Line style is unicode.
Null display is NULL.
Pager is used for long output.
Record separator is newline.


So that it also serves a reminder on how to subsequently
change them


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


Re: [HACKERS] psql and pset without any arguments

2013-06-29 Thread Pavel Stehule
2013/6/29 Erik Rijkers e...@xs4all.nl:
 On Sat, June 29, 2013 01:08, Gilles Darold wrote:
  Here is a sample output:

 (postgres@[local]:5494) [postgres]  \pset
 Output format is aligned.
 Border style is 2.
 Expanded display is used automatically.
 Null display is NULL.
 Field separator is |.
 Tuples only is off.
 Title is unset.
 Table attributes unset.
 Line style is unicode.
 Pager is used for long output.
 Record separator is newline.
 (postgres@[local]:5494) [postgres] 


 +1

 This seems handy.  Maybe it could be improved
 a bit with the keyboard shortcuts prefixed, like so:

 (postgres@[local]:5494) [postgres]  \pset
 \a  Output format is aligned.
 \x  Expanded display is used automatically.
 \f  Field separator is |.
 \t  Tuples only is off.
 \C  Title is unset.
 \T  Table attributes unset.
 Border style is 2.
 Line style is unicode.
 Null display is NULL.
 Pager is used for long output.
 Record separator is newline.


it is less readable - and same info you can get with \?

Regards

Pavel


 So that it also serves a reminder on how to subsequently
 change them


 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


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


Re: [HACKERS] psql and pset without any arguments

2013-06-29 Thread Gilles Darold
Le 29/06/2013 13:55, Erik Rijkers a écrit :
 On Sat, June 29, 2013 01:08, Gilles Darold wrote:
  Here is a sample output:

 (postgres@[local]:5494) [postgres]  \pset
 Output format is aligned.
 Border style is 2.
 Expanded display is used automatically.
 Null display is NULL.
 Field separator is |.
 Tuples only is off.
 Title is unset.
 Table attributes unset.
 Line style is unicode.
 Pager is used for long output.
 Record separator is newline.
 (postgres@[local]:5494) [postgres] 

 +1

 This seems handy.  Maybe it could be improved
 a bit with the keyboard shortcuts prefixed, like so:

 (postgres@[local]:5494) [postgres]  \pset
 \a  Output format is aligned.
 \x  Expanded display is used automatically.
 \f  Field separator is |.
 \t  Tuples only is off.
 \C  Title is unset.
 \T  Table attributes unset.
 Border style is 2.
 Line style is unicode.
 Null display is NULL.
 Pager is used for long output.
 Record separator is newline.


 So that it also serves a reminder on how to subsequently
 change them

My first though was to print something like \set output, but why not
reuse the original code/output when \pset is used ?

This second choice has three main advantages :

 * Information shown is the same everywhere
 * Backward compatibility with \pset output
 * Avoid code redundancy

About shortcut I'm agree with Pavel that it is less readable and already
in the help, \? is the big reminder :-)

Regards,

-- 
Gilles Darold
http://dalibo.com - http://dalibo.org



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


[HACKERS] psql and pset without any arguments

2013-06-28 Thread Gilles Darold
Hi,

I was looking at psql 8.3 documention about \pset options and saw that
there was the following note :

Note: It is an error to call \pset without any arguments. In the
future this case might show the current status of all printing options.

I looked backward and forward to find that this note is present in all
versions since 7.1 up to 9.3, maybe it is time to add this little feature.

I've attached a patch to add the usage of the \pset command without any
arguments to displays current status of all printing options instead of
the error message. Here is a sample output:

(postgres@[local]:5494) [postgres]  \pset
Output format is aligned.
Border style is 2.
Expanded display is used automatically.
Null display is NULL.
Field separator is |.
Tuples only is off.
Title is unset.
Table attributes unset.
Line style is unicode.
Pager is used for long output.
Record separator is newline.
(postgres@[local]:5494) [postgres] 

To avoid redundant code I've added a new method printPsetInfo() so that
do_pset() and exec_command() will used the same output message, they are
all in src/bin/psql/command.c. For example:

(postgres@[local]:5494) [postgres]  \pset null 'NULL'
Null display is NULL.
(postgres@[local]:5494) [postgres] 

The patch print all variables information from struct printTableOpt when
\pset is given without any arguments and also update documentation.

Let me know if there's any additional work to do on this basic patch or
something that I've omitted.

Best regards,

-- 
Gilles Darold
http://dalibo.com - http://dalibo.org

diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index 574db5c..a3bf555 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -2272,13 +2272,9 @@ lo_import 152801
 /para
 /tip
 
-note
-para
-It is an error to call command\pset/command without any
-arguments. In the future this case might show the current status
-of all printing options.
+paracommand\pset/ without any arguments displays current status
+ of all printing options.
 /para
-/note
 
 /listitem
   /varlistentry
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index 351e684..daf7ac7 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -68,6 +68,7 @@ static int	strip_lineno_from_funcdesc(char *func);
 static void minimal_error_message(PGresult *res);
 
 static void printSSLInfo(void);
+static bool printPsetInfo(const char *param, struct printQueryOpt *popt);
 
 #ifdef WIN32
 static void checkWin32Codepage(void);
@@ -1045,8 +1046,16 @@ exec_command(const char *cmd,
 
 		if (!opt0)
 		{
-			psql_error(\\%s: missing required argument\n, cmd);
-			success = false;
+			size_t i;
+			/* list all variables */
+			static const char *const my_list[] = {format, border,
+expanded, null, fieldsep, tuples_only, title,
+tableattr, linestyle, pager, recordsep, NULL};
+			for (i = 0; my_list[i] != NULL; i++) {
+printPsetInfo(my_list[i], pset.popt);
+			}
+
+			success = true;
 		}
 		else
 			success = do_pset(opt0, opt1, pset.popt, pset.quiet);
@@ -2275,8 +2284,6 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
 			return false;
 		}
 
-		if (!quiet)
-			printf(_(Output format is %s.\n), _align2string(popt-topt.format));
 	}
 
 	/* set table line style */
@@ -2295,10 +2302,6 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
 			psql_error(\\pset: allowed line styles are ascii, old-ascii, unicode\n);
 			return false;
 		}
-
-		if (!quiet)
-			printf(_(Line style is %s.\n),
-   get_line_style(popt-topt)-name);
 	}
 
 	/* set border style/width */
@@ -2306,9 +2309,6 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
 	{
 		if (value)
 			popt-topt.border = atoi(value);
-
-		if (!quiet)
-			printf(_(Border style is %d.\n), popt-topt.border);
 	}
 
 	/* set expanded/vertical mode */
@@ -2320,15 +2320,6 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
 			popt-topt.expanded = ParseVariableBool(value);
 		else
 			popt-topt.expanded = !popt-topt.expanded;
-		if (!quiet)
-		{
-			if (popt-topt.expanded == 1)
-printf(_(Expanded display is on.\n));
-			else if (popt-topt.expanded == 2)
-printf(_(Expanded display is used automatically.\n));
-			else
-printf(_(Expanded display is off.\n));
-		}
 	}
 
 	/* locale-aware numeric output */
@@ -2338,13 +2329,6 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
 			popt-topt.numericLocale = ParseVariableBool(value);
 		else
 			popt-topt.numericLocale = !popt-topt.numericLocale;
-		if (!quiet)
-		{
-			if (popt-topt.numericLocale)
-puts(_(Showing locale-adjusted numeric output.));
-			else
-