Re: [HACKERS] psql: show only failed queries

2014-08-11 Thread Fujii Masao
On Sat, Aug 9, 2014 at 4:16 AM, Pavel Stehule pavel.steh...@gmail.com wrote:
 Hi


 2014-08-08 13:58 GMT+02:00 Fujii Masao masao.fu...@gmail.com:

 On Fri, Aug 8, 2014 at 4:31 AM, Pavel Stehule pavel.steh...@gmail.com
 wrote:
 
 
 
  2014-08-07 7:10 GMT+02:00 Fujii Masao masao.fu...@gmail.com:
 
  On Thu, Aug 7, 2014 at 6:26 AM, Pavel Stehule pavel.steh...@gmail.com
  wrote:
   Hello
  
   updated version patch in attachment
 
  Thanks! But ISTM you forgot to attached the patch.
 
 
  grr .. I am sorry

 No problem. Thanks for the patch! Attached is the revised version of the
 patch.

   +/* all psql known variables are included in list by default */
   +for (known_varname = known_varnames; *known_varname;
   known_varname++)
   +varnames[nvars++] = pg_strdup(*known_varname);
  
   Don't we need to append both prefix and suffix to even known
   variables?
  
  
   ??? I am not sure if I understand well - probably system read only
   variables as DBNAME, USER, VERSION should not be there
 
  I had that question because complete_from_variables() is also called by
  the
  tab-completion of \echo : and it shows half-baked variables list. So
  I thought probably we need to change complete_from_variables() more to
  fix the problem.
 
 
  I understand now.
 
  I fixed it.
 
  I have a question.\echo probably should not to show empty known
  variable.
 
  data for autocomplete for \echo should be same as result of \set

 Agreed. I think that only the variables having the set values should be
 displayed in \echo : case. So I modified complete_from_variables()
 so that the unset variables are not shown in that case but all the
 variables
 are shown in the tab-completion of \set.

   +else if (strcmp(prev2_wd, \\set) == 0)
   +{
   +if (strcmp(prev_wd, AUTOCOMMIT) == 0)
  
   ISTM that some psql variables like IGNOREEOF are not there. Why not?
  
  
   yes, there are not complete for DBNAME, ENCODING, FETCH_COUNT,
   HISTCONTROL,
   HISTFILE, HISTSIZE, HOST, IGNOREEOFF, PROMPT*,USER,  VERSION
  
   There are more reasons:
  
   * paremeter is not a enum (string, number or both): FETCH_COUNT,
   PROMPT,
   HISTSIZE, ..
  
   * variable is pseudo read only  - change has not any effect: DBNAME,
   ENCODING, VERSION
 
  So HISTCONTROL should be there because it doesn't have such reasons at
  all?
 
 
  yes

 ISTM that you forgot to add HISTCONTROL to your patch. So I just added
 that.

 I added the tab-completion for \unset command. Like \echo :, only
 the variables having the set values should be displayed in \unset case.


 perfect



 I changed complete_from_variables() so that it checks the memory size of
 the variable array even when appending the known variables. If the memory
 size is not enough, it's dynamically increased. Practically this check
 would
 not be required because the initial size of the array is enough larger
 than
 the number of the known variables. I added this as the safe-guard.

 Typo: IGNOREEOFF - IGNOREEOF

 I removed the value none from the value list of ECHO because it's not
 documented and a user might get confused when he or she sees the
 undocumented
 value none. Thought?


 isn't better to fix doc? I don't know any reason why we should not to
 support none

I'm OK with this. The attached patch adds the support of none value both
in ECHO and HISTCONTROL variables (because HISTCONTROL had the same
problem as ECHO had), and also adds the description of that value into
the document.

 I looked to code, you removed a check against duplicate varname in list. Is
 it ok?

Oh, just revived that code.

Regards,

-- 
Fujii Masao
*** a/doc/src/sgml/ref/psql-ref.sgml
--- b/doc/src/sgml/ref/psql-ref.sgml
***
*** 2827,2833  bar
  they are sent to the server. The switch for this is
  option-e/option. If set to literalerrors/literal then only
  failed queries are displayed on standard error output. The switch
! for this is option-b/option.
  /para
  /listitem
/varlistentry
--- 2827,2835 
  they are sent to the server. The switch for this is
  option-e/option. If set to literalerrors/literal then only
  failed queries are displayed on standard error output. The switch
! for this is option-b/option. If unset, or if set to
! literalnone/literal (or any other value than those above) then
! no queries are displayed.
  /para
  /listitem
/varlistentry
***
*** 2892,2899  bar
   list. If set to a value of literalignoredups/literal, lines
   matching the previous history line are not entered. A value of
   literalignoreboth/literal combines the two options. If
!  unset, or if set to any other value than those above, all lines
!  read in interactive mode are saved on the history list.
  /para
  note
  para
--- 2894,2902 
   list. If set to a 

Re: [HACKERS] psql: show only failed queries

2014-08-11 Thread Pavel Stehule
2014-08-11 14:59 GMT+02:00 Fujii Masao masao.fu...@gmail.com:

 On Sat, Aug 9, 2014 at 4:16 AM, Pavel Stehule pavel.steh...@gmail.com
 wrote:
  Hi
 
 
  2014-08-08 13:58 GMT+02:00 Fujii Masao masao.fu...@gmail.com:
 
  On Fri, Aug 8, 2014 at 4:31 AM, Pavel Stehule pavel.steh...@gmail.com
  wrote:
  
  
  
   2014-08-07 7:10 GMT+02:00 Fujii Masao masao.fu...@gmail.com:
  
   On Thu, Aug 7, 2014 at 6:26 AM, Pavel Stehule 
 pavel.steh...@gmail.com
   wrote:
Hello
   
updated version patch in attachment
  
   Thanks! But ISTM you forgot to attached the patch.
  
  
   grr .. I am sorry
 
  No problem. Thanks for the patch! Attached is the revised version of the
  patch.
 
+/* all psql known variables are included in list by default
 */
+for (known_varname = known_varnames; *known_varname;
known_varname++)
+varnames[nvars++] = pg_strdup(*known_varname);
   
Don't we need to append both prefix and suffix to even known
variables?
   
   
??? I am not sure if I understand well - probably system read
 only
variables as DBNAME, USER, VERSION should not be there
  
   I had that question because complete_from_variables() is also called
 by
   the
   tab-completion of \echo : and it shows half-baked variables list.
 So
   I thought probably we need to change complete_from_variables() more
 to
   fix the problem.
  
  
   I understand now.
  
   I fixed it.
  
   I have a question.\echo probably should not to show empty known
   variable.
  
   data for autocomplete for \echo should be same as result of \set
 
  Agreed. I think that only the variables having the set values should be
  displayed in \echo : case. So I modified complete_from_variables()
  so that the unset variables are not shown in that case but all the
  variables
  are shown in the tab-completion of \set.
 
+else if (strcmp(prev2_wd, \\set) == 0)
+{
+if (strcmp(prev_wd, AUTOCOMMIT) == 0)
   
ISTM that some psql variables like IGNOREEOF are not there. Why
 not?
   
   
yes, there are not complete for DBNAME, ENCODING, FETCH_COUNT,
HISTCONTROL,
HISTFILE, HISTSIZE, HOST, IGNOREEOFF, PROMPT*,USER,  VERSION
   
There are more reasons:
   
* paremeter is not a enum (string, number or both): FETCH_COUNT,
PROMPT,
HISTSIZE, ..
   
* variable is pseudo read only  - change has not any effect:
 DBNAME,
ENCODING, VERSION
  
   So HISTCONTROL should be there because it doesn't have such reasons
 at
   all?
  
  
   yes
 
  ISTM that you forgot to add HISTCONTROL to your patch. So I just added
  that.
 
  I added the tab-completion for \unset command. Like \echo :, only
  the variables having the set values should be displayed in \unset
 case.
 
 
  perfect
 
 
 
  I changed complete_from_variables() so that it checks the memory size of
  the variable array even when appending the known variables. If the
 memory
  size is not enough, it's dynamically increased. Practically this check
  would
  not be required because the initial size of the array is enough larger
  than
  the number of the known variables. I added this as the safe-guard.
 
  Typo: IGNOREEOFF - IGNOREEOF
 
  I removed the value none from the value list of ECHO because it's
 not
  documented and a user might get confused when he or she sees the
  undocumented
  value none. Thought?
 
 
  isn't better to fix doc? I don't know any reason why we should not to
  support none

 I'm OK with this. The attached patch adds the support of none value both
 in ECHO and HISTCONTROL variables (because HISTCONTROL had the same
 problem as ECHO had), and also adds the description of that value into
 the document.

  I looked to code, you removed a check against duplicate varname in list.
 Is
  it ok?

 Oh, just revived that code.


yes, It is looking well

regards

Pavel



 Regards,

 --
 Fujii Masao



Re: [HACKERS] psql: show only failed queries

2014-08-11 Thread Fujii Masao
On Tue, Aug 12, 2014 at 4:41 AM, Pavel Stehule pavel.steh...@gmail.com wrote:



 2014-08-11 14:59 GMT+02:00 Fujii Masao masao.fu...@gmail.com:

 On Sat, Aug 9, 2014 at 4:16 AM, Pavel Stehule pavel.steh...@gmail.com
 wrote:
  Hi
 
 
  2014-08-08 13:58 GMT+02:00 Fujii Masao masao.fu...@gmail.com:
 
  On Fri, Aug 8, 2014 at 4:31 AM, Pavel Stehule pavel.steh...@gmail.com
  wrote:
  
  
  
   2014-08-07 7:10 GMT+02:00 Fujii Masao masao.fu...@gmail.com:
  
   On Thu, Aug 7, 2014 at 6:26 AM, Pavel Stehule
   pavel.steh...@gmail.com
   wrote:
Hello
   
updated version patch in attachment
  
   Thanks! But ISTM you forgot to attached the patch.
  
  
   grr .. I am sorry
 
  No problem. Thanks for the patch! Attached is the revised version of
  the
  patch.
 
+/* all psql known variables are included in list by default
*/
+for (known_varname = known_varnames; *known_varname;
known_varname++)
+varnames[nvars++] = pg_strdup(*known_varname);
   
Don't we need to append both prefix and suffix to even known
variables?
   
   
??? I am not sure if I understand well - probably system read
only
variables as DBNAME, USER, VERSION should not be there
  
   I had that question because complete_from_variables() is also called
   by
   the
   tab-completion of \echo : and it shows half-baked variables list.
   So
   I thought probably we need to change complete_from_variables() more
   to
   fix the problem.
  
  
   I understand now.
  
   I fixed it.
  
   I have a question.\echo probably should not to show empty known
   variable.
  
   data for autocomplete for \echo should be same as result of \set
 
  Agreed. I think that only the variables having the set values should be
  displayed in \echo : case. So I modified complete_from_variables()
  so that the unset variables are not shown in that case but all the
  variables
  are shown in the tab-completion of \set.
 
+else if (strcmp(prev2_wd, \\set) == 0)
+{
+if (strcmp(prev_wd, AUTOCOMMIT) == 0)
   
ISTM that some psql variables like IGNOREEOF are not there. Why
not?
   
   
yes, there are not complete for DBNAME, ENCODING, FETCH_COUNT,
HISTCONTROL,
HISTFILE, HISTSIZE, HOST, IGNOREEOFF, PROMPT*,USER,  VERSION
   
There are more reasons:
   
* paremeter is not a enum (string, number or both): FETCH_COUNT,
PROMPT,
HISTSIZE, ..
   
* variable is pseudo read only  - change has not any effect:
DBNAME,
ENCODING, VERSION
  
   So HISTCONTROL should be there because it doesn't have such reasons
   at
   all?
  
  
   yes
 
  ISTM that you forgot to add HISTCONTROL to your patch. So I just added
  that.
 
  I added the tab-completion for \unset command. Like \echo :, only
  the variables having the set values should be displayed in \unset
  case.
 
 
  perfect
 
 
 
  I changed complete_from_variables() so that it checks the memory size
  of
  the variable array even when appending the known variables. If the
  memory
  size is not enough, it's dynamically increased. Practically this check
  would
  not be required because the initial size of the array is enough larger
  than
  the number of the known variables. I added this as the safe-guard.
 
  Typo: IGNOREEOFF - IGNOREEOF
 
  I removed the value none from the value list of ECHO because it's
  not
  documented and a user might get confused when he or she sees the
  undocumented
  value none. Thought?
 
 
  isn't better to fix doc? I don't know any reason why we should not to
  support none

 I'm OK with this. The attached patch adds the support of none value both
 in ECHO and HISTCONTROL variables (because HISTCONTROL had the same
 problem as ECHO had), and also adds the description of that value into
 the document.

  I looked to code, you removed a check against duplicate varname in list.
  Is
  it ok?

 Oh, just revived that code.


 yes, It is looking well

Ok, committed!

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


Re: [HACKERS] psql: show only failed queries

2014-08-11 Thread Pavel Stehule
 
  Oh, just revived that code.
 
 
  yes, It is looking well

 Ok, committed!


super

thank you very much

Regards

Pavel



 Regards,

 --
 Fujii Masao



Re: [HACKERS] psql: show only failed queries

2014-08-08 Thread Fujii Masao
On Fri, Aug 8, 2014 at 4:31 AM, Pavel Stehule pavel.steh...@gmail.com wrote:



 2014-08-07 7:10 GMT+02:00 Fujii Masao masao.fu...@gmail.com:

 On Thu, Aug 7, 2014 at 6:26 AM, Pavel Stehule pavel.steh...@gmail.com
 wrote:
  Hello
 
  updated version patch in attachment

 Thanks! But ISTM you forgot to attached the patch.


 grr .. I am sorry

No problem. Thanks for the patch! Attached is the revised version of the patch.

  +/* all psql known variables are included in list by default */
  +for (known_varname = known_varnames; *known_varname;
  known_varname++)
  +varnames[nvars++] = pg_strdup(*known_varname);
 
  Don't we need to append both prefix and suffix to even known variables?
 
 
  ??? I am not sure if I understand well - probably system read only
  variables as DBNAME, USER, VERSION should not be there

 I had that question because complete_from_variables() is also called by
 the
 tab-completion of \echo : and it shows half-baked variables list. So
 I thought probably we need to change complete_from_variables() more to
 fix the problem.


 I understand now.

 I fixed it.

 I have a question.\echo probably should not to show empty known variable.

 data for autocomplete for \echo should be same as result of \set

Agreed. I think that only the variables having the set values should be
displayed in \echo : case. So I modified complete_from_variables()
so that the unset variables are not shown in that case but all the variables
are shown in the tab-completion of \set.

  +else if (strcmp(prev2_wd, \\set) == 0)
  +{
  +if (strcmp(prev_wd, AUTOCOMMIT) == 0)
 
  ISTM that some psql variables like IGNOREEOF are not there. Why not?
 
 
  yes, there are not complete for DBNAME, ENCODING, FETCH_COUNT,
  HISTCONTROL,
  HISTFILE, HISTSIZE, HOST, IGNOREEOFF, PROMPT*,USER,  VERSION
 
  There are more reasons:
 
  * paremeter is not a enum (string, number or both): FETCH_COUNT, PROMPT,
  HISTSIZE, ..
 
  * variable is pseudo read only  - change has not any effect: DBNAME,
  ENCODING, VERSION

 So HISTCONTROL should be there because it doesn't have such reasons at
 all?


 yes

ISTM that you forgot to add HISTCONTROL to your patch. So I just added that.

I added the tab-completion for \unset command. Like \echo :, only
the variables having the set values should be displayed in \unset case.

I changed complete_from_variables() so that it checks the memory size of
the variable array even when appending the known variables. If the memory
size is not enough, it's dynamically increased. Practically this check would
not be required because the initial size of the array is enough larger than
the number of the known variables. I added this as the safe-guard.

Typo: IGNOREEOFF - IGNOREEOF

I removed the value none from the value list of ECHO because it's not
documented and a user might get confused when he or she sees the undocumented
value none. Thought?

Regards,

-- 
Fujii Masao
*** a/src/bin/psql/tab-complete.c
--- b/src/bin/psql/tab-complete.c
***
*** 813,820  static char *_complete_from_query(int is_schema_query,
  	 const char *text, int state);
  static char *complete_from_list(const char *text, int state);
  static char *complete_from_const(const char *text, int state);
  static char **complete_from_variables(const char *text,
! 		const char *prefix, const char *suffix);
  static char *complete_from_files(const char *text, int state);
  
  static char *pg_strdup_keyword_case(const char *s, const char *ref);
--- 813,823 
  	 const char *text, int state);
  static char *complete_from_list(const char *text, int state);
  static char *complete_from_const(const char *text, int state);
+ static void append_variable_names(char ***varnames, int *nvars,
+   int *maxvars, const char *varname,
+   const char *prefix, const char *suffix);
  static char **complete_from_variables(const char *text,
! 	  const char *prefix, const char *suffix, bool need_value);
  static char *complete_from_files(const char *text, int state);
  
  static char *pg_strdup_keyword_case(const char *s, const char *ref);
***
*** 925,935  psql_completion(const char *text, int start, int end)
  	else if (text[0] == ':'  text[1] != ':')
  	{
  		if (text[1] == '\'')
! 			matches = complete_from_variables(text, :', ');
  		else if (text[1] == '')
! 			matches = complete_from_variables(text, :\, \);
  		else
! 			matches = complete_from_variables(text, :, );
  	}
  
  	/* If no previous word, suggest one of the basic sql commands */
--- 928,938 
  	else if (text[0] == ':'  text[1] != ':')
  	{
  		if (text[1] == '\'')
! 			matches = complete_from_variables(text, :', ', true);
  		else if (text[1] == '')
! 			matches = complete_from_variables(text, :\, \, true);
  		else
! 			matches = complete_from_variables(text, :, , true);
  	}
  
  	/* If no previous word, suggest one of the basic sql commands */
***
*** 3604,3612  

Re: [HACKERS] psql: show only failed queries

2014-08-08 Thread Pavel Stehule
Hi


2014-08-08 13:58 GMT+02:00 Fujii Masao masao.fu...@gmail.com:

 On Fri, Aug 8, 2014 at 4:31 AM, Pavel Stehule pavel.steh...@gmail.com
 wrote:
 
 
 
  2014-08-07 7:10 GMT+02:00 Fujii Masao masao.fu...@gmail.com:
 
  On Thu, Aug 7, 2014 at 6:26 AM, Pavel Stehule pavel.steh...@gmail.com
  wrote:
   Hello
  
   updated version patch in attachment
 
  Thanks! But ISTM you forgot to attached the patch.
 
 
  grr .. I am sorry

 No problem. Thanks for the patch! Attached is the revised version of the
 patch.

   +/* all psql known variables are included in list by default */
   +for (known_varname = known_varnames; *known_varname;
   known_varname++)
   +varnames[nvars++] = pg_strdup(*known_varname);
  
   Don't we need to append both prefix and suffix to even known
 variables?
  
  
   ??? I am not sure if I understand well - probably system read only
   variables as DBNAME, USER, VERSION should not be there
 
  I had that question because complete_from_variables() is also called by
  the
  tab-completion of \echo : and it shows half-baked variables list. So
  I thought probably we need to change complete_from_variables() more to
  fix the problem.
 
 
  I understand now.
 
  I fixed it.
 
  I have a question.\echo probably should not to show empty known variable.
 
  data for autocomplete for \echo should be same as result of \set

 Agreed. I think that only the variables having the set values should be
 displayed in \echo : case. So I modified complete_from_variables()
 so that the unset variables are not shown in that case but all the
 variables
 are shown in the tab-completion of \set.

   +else if (strcmp(prev2_wd, \\set) == 0)
   +{
   +if (strcmp(prev_wd, AUTOCOMMIT) == 0)
  
   ISTM that some psql variables like IGNOREEOF are not there. Why not?
  
  
   yes, there are not complete for DBNAME, ENCODING, FETCH_COUNT,
   HISTCONTROL,
   HISTFILE, HISTSIZE, HOST, IGNOREEOFF, PROMPT*,USER,  VERSION
  
   There are more reasons:
  
   * paremeter is not a enum (string, number or both): FETCH_COUNT,
 PROMPT,
   HISTSIZE, ..
  
   * variable is pseudo read only  - change has not any effect: DBNAME,
   ENCODING, VERSION
 
  So HISTCONTROL should be there because it doesn't have such reasons at
  all?
 
 
  yes

 ISTM that you forgot to add HISTCONTROL to your patch. So I just added
 that.

 I added the tab-completion for \unset command. Like \echo :, only
 the variables having the set values should be displayed in \unset case.


perfect



 I changed complete_from_variables() so that it checks the memory size of
 the variable array even when appending the known variables. If the memory
 size is not enough, it's dynamically increased. Practically this check
 would
 not be required because the initial size of the array is enough larger than
 the number of the known variables. I added this as the safe-guard.

 Typo: IGNOREEOFF - IGNOREEOF

 I removed the value none from the value list of ECHO because it's not
 documented and a user might get confused when he or she sees the
 undocumented
 value none. Thought?


isn't better to fix doc? I don't know any reason why we should not to
support none

I looked to code, you removed a check against duplicate varname in list. Is
it ok?

Regards

Pavel




 Regards,

 --
 Fujii Masao



Re: [HACKERS] psql: show only failed queries

2014-08-07 Thread Pavel Stehule
2014-08-07 7:10 GMT+02:00 Fujii Masao masao.fu...@gmail.com:

 On Thu, Aug 7, 2014 at 6:26 AM, Pavel Stehule pavel.steh...@gmail.com
 wrote:
  Hello
 
  updated version patch in attachment

 Thanks! But ISTM you forgot to attached the patch.


grr .. I am sorry



  +/* all psql known variables are included in list by default */
  +for (known_varname = known_varnames; *known_varname;
 known_varname++)
  +varnames[nvars++] = pg_strdup(*known_varname);
 
  Don't we need to append both prefix and suffix to even known variables?
 
 
  ??? I am not sure if I understand well - probably system read only
  variables as DBNAME, USER, VERSION should not be there

 I had that question because complete_from_variables() is also called by the
 tab-completion of \echo : and it shows half-baked variables list. So
 I thought probably we need to change complete_from_variables() more to
 fix the problem.


I understand now.

I fixed it.

I have a question.\echo probably should not to show empty known variable.

data for autocomplete for \echo should be same as result of \set




  +else if (strcmp(prev2_wd, \\set) == 0)
  +{
  +if (strcmp(prev_wd, AUTOCOMMIT) == 0)
 
  ISTM that some psql variables like IGNOREEOF are not there. Why not?
 
 
  yes, there are not complete for DBNAME, ENCODING, FETCH_COUNT,
 HISTCONTROL,
  HISTFILE, HISTSIZE, HOST, IGNOREEOFF, PROMPT*,USER,  VERSION
 
  There are more reasons:
 
  * paremeter is not a enum (string, number or both): FETCH_COUNT, PROMPT,
  HISTSIZE, ..
 
  * variable is pseudo read only  - change has not any effect: DBNAME,
  ENCODING, VERSION

 So HISTCONTROL should be there because it doesn't have such reasons at all?


yes

Pavel


 Regards,

 --
 Fujii Masao

commit bacfdc0e03219265aeee34b78f7ec9d272d49f72
Author: Pavel Stehule pavel.steh...@gooddata.com
Date:   Wed Aug 6 23:05:42 2014 +0200

warnings and typo fixed

diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 24e60b7..b94ed63 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -3608,6 +3608,79 @@ psql_completion(const char *text, int start, int end)
 	{
 		matches = complete_from_variables(text, , );
 	}
+	else if (strcmp(prev2_wd, \\set) == 0)
+	{
+		if (strcmp(prev_wd, AUTOCOMMIT) == 0)
+		{
+			static const char *const my_list[] =
+			{on, off, interactive, NULL};
+
+			COMPLETE_WITH_LIST_CS(my_list);
+		}
+		else if (strcmp(prev_wd, COMP_KEYWORD_CASE) == 0)
+		{
+			static const char *const my_list[] =
+			{lower, upper, preserve-lower, preserve-upper, NULL};
+
+			COMPLETE_WITH_LIST_CS(my_list);
+		}
+		else if (strcmp(prev_wd, ECHO) == 0)
+		{
+			static const char *const my_list[] =
+			{none, errors, queries, all, NULL};
+
+			COMPLETE_WITH_LIST_CS(my_list);
+		}
+		else if (strcmp(prev_wd, ECHO_HIDDEN) == 0)
+		{
+			static const char *const my_list[] =
+			{noexec, off, on, NULL};
+
+			COMPLETE_WITH_LIST_CS(my_list);
+		}
+		else if (strcmp(prev_wd, ON_ERROR_ROLLBACK) == 0)
+		{
+			static const char *const my_list[] =
+			{on, off, interactive, NULL};
+
+			COMPLETE_WITH_LIST_CS(my_list);
+		}
+		else if (strcmp(prev_wd, ON_ERROR_STOP) == 0)
+		{
+			static const char *const my_list[] =
+			{on, off, NULL};
+
+			COMPLETE_WITH_LIST_CS(my_list);
+		}
+		else if (strcmp(prev_wd, QUIET) == 0)
+		{
+			static const char *const my_list[] =
+			{on, off, NULL};
+
+			COMPLETE_WITH_LIST_CS(my_list);
+		}
+		else if (strcmp(prev_wd, SINGLELINE) == 0)
+		{
+			static const char *const my_list[] =
+			{on, off, NULL};
+
+			COMPLETE_WITH_LIST_CS(my_list);
+		}
+		else if (strcmp(prev_wd, SINGLESTEP) == 0)
+		{
+			static const char *const my_list[] =
+			{on, off, NULL};
+
+			COMPLETE_WITH_LIST_CS(my_list);
+		}
+		else if (strcmp(prev_wd, VERBOSITY) == 0)
+		{
+			static const char *const my_list[] =
+			{default, verbose, terse, NULL};
+
+			COMPLETE_WITH_LIST_CS(my_list);
+		}
+	}
 	else if (strcmp(prev_wd, \\sf) == 0 || strcmp(prev_wd, \\sf+) == 0)
 		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_functions, NULL);
 	else if (strcmp(prev_wd, \\cd) == 0 ||
@@ -4062,28 +4135,61 @@ complete_from_variables(const char *text, const char *prefix, const char *suffix
 {
 	char	  **matches;
 	char	  **varnames;
+	static const char **known_varname;
 	int			nvars = 0;
 	int			maxvars = 100;
 	int			i;
 	struct _variable *ptr;
 
+	static const char *known_varnames[] = {
+		AUTOCOMMIT, COMP_KEYWORD_CASE, DBNAME, ECHO, ECHO_HIDDEN, ENCODING,
+		FETCH_COUNT, HISTCONTROL, HISTFILE, HISTSIZE, HOST, IGNOREEOFF,
+		LASTOID, ON_ERROR_ROLLBACK, ON_ERROR_STOP, PORT, PROMPT1, PROMPT2,
+		PROMPT3, QUIET, SINGLELINE, SINGLESTEP, USER, VERBOSITY,
+		NULL
+	};
+
 	varnames = (char **) pg_malloc((maxvars + 1) * sizeof(char *));
 
+	/* all psql known variables are included in list by default */
+	for (known_varname = known_varnames; *known_varname; known_varname++)
+		varnames[nvars++] = psprintf(%s%s%s, prefix, *known_varname, suffix);
+
 	for (ptr = 

Re: [HACKERS] psql: show only failed queries

2014-08-06 Thread Pavel Stehule
Hello

updated version patch in attachment

2014-08-05 13:31 GMT+02:00 Fujii Masao masao.fu...@gmail.com:

 On Wed, Jul 16, 2014 at 4:34 AM, Pavel Stehule pavel.steh...@gmail.com
 wrote:
 
 
 
  2014-07-15 12:07 GMT+02:00 Fujii Masao masao.fu...@gmail.com:
 
  On Tue, Jul 15, 2014 at 7:01 PM, Pavel Stehule pavel.steh...@gmail.com
 
  wrote:
  
  
  
   2014-07-15 11:29 GMT+02:00 Fujii Masao masao.fu...@gmail.com:
  
   On Thu, Jul 10, 2014 at 9:56 PM, Pavel Stehule
   pavel.steh...@gmail.com
   wrote:
Hello
   
here is a proposed patch - autocomplete for known psql variable
content
  
   Even after applying the patch, the following psql variables were not
   displayed
   on the tab-completion of \set command.
  
   HISTFILE
   HISTSIZE
   HOST
   IGNOREEOF
   LASTOID
  
   I'm not sure if it's worth displaying all of them on the
 tab-completion
   of
   \set
   because it seems strange to change some of them by \set command, for
   example
   HOST, though.
  
  
   For these variables are not default - so doesn't exist and cannot be
   completed by default.
  
   there are two fix:
  
   a) fix autocomplete source - preferred
 
  +1
 
 
  here is the patch

 Thanks for the patch!

 I got the following compiler warnings.

 tab-complete.c:4155: warning: assignment discards qualifiers from
 pointer target type
 tab-complete.c:4166: warning: assignment discards qualifiers from
 pointer target type


fixed


 +FETCH_COUNT, HISTCONTROL, HISTFILE, HISTSIZE, HOST,
 IGNOREOFF,

 Typo: IGNOREOFF - IGNOREEOF


fixed


 +/* all psql known variables are included in list by default */
 +for (known_varname = known_varnames; *known_varname; known_varname++)
 +varnames[nvars++] = pg_strdup(*known_varname);

 Don't we need to append both prefix and suffix to even known variables?


??? I am not sure if I understand well - probably system read only
variables as DBNAME, USER, VERSION should not be there



 +else if (strcmp(prev2_wd, \\set) == 0)
 +{
 +if (strcmp(prev_wd, AUTOCOMMIT) == 0)

 ISTM that some psql variables like IGNOREEOF are not there. Why not?


yes, there are not complete for DBNAME, ENCODING, FETCH_COUNT, HISTCONTROL,
HISTFILE, HISTSIZE, HOST, IGNOREEOFF, PROMPT*,USER,  VERSION

There are more reasons:

* paremeter is not a enum (string, number or both): FETCH_COUNT, PROMPT,
HISTSIZE, ..

* variable is pseudo read only  - change has not any effect: DBNAME,
ENCODING, VERSION

Regards

Pavel



 Regards,

 --
 Fujii Masao



Re: [HACKERS] psql: show only failed queries

2014-08-06 Thread Fujii Masao
On Thu, Aug 7, 2014 at 6:26 AM, Pavel Stehule pavel.steh...@gmail.com wrote:
 Hello

 updated version patch in attachment

Thanks! But ISTM you forgot to attached the patch.

 +/* all psql known variables are included in list by default */
 +for (known_varname = known_varnames; *known_varname; known_varname++)
 +varnames[nvars++] = pg_strdup(*known_varname);

 Don't we need to append both prefix and suffix to even known variables?


 ??? I am not sure if I understand well - probably system read only
 variables as DBNAME, USER, VERSION should not be there

I had that question because complete_from_variables() is also called by the
tab-completion of \echo : and it shows half-baked variables list. So
I thought probably we need to change complete_from_variables() more to
fix the problem.

 +else if (strcmp(prev2_wd, \\set) == 0)
 +{
 +if (strcmp(prev_wd, AUTOCOMMIT) == 0)

 ISTM that some psql variables like IGNOREEOF are not there. Why not?


 yes, there are not complete for DBNAME, ENCODING, FETCH_COUNT, HISTCONTROL,
 HISTFILE, HISTSIZE, HOST, IGNOREEOFF, PROMPT*,USER,  VERSION

 There are more reasons:

 * paremeter is not a enum (string, number or both): FETCH_COUNT, PROMPT,
 HISTSIZE, ..

 * variable is pseudo read only  - change has not any effect: DBNAME,
 ENCODING, VERSION

So HISTCONTROL should be there because it doesn't have such reasons at all?

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


Re: [HACKERS] psql: show only failed queries

2014-08-05 Thread Fujii Masao
On Wed, Jul 16, 2014 at 4:34 AM, Pavel Stehule pavel.steh...@gmail.com wrote:



 2014-07-15 12:07 GMT+02:00 Fujii Masao masao.fu...@gmail.com:

 On Tue, Jul 15, 2014 at 7:01 PM, Pavel Stehule pavel.steh...@gmail.com
 wrote:
 
 
 
  2014-07-15 11:29 GMT+02:00 Fujii Masao masao.fu...@gmail.com:
 
  On Thu, Jul 10, 2014 at 9:56 PM, Pavel Stehule
  pavel.steh...@gmail.com
  wrote:
   Hello
  
   here is a proposed patch - autocomplete for known psql variable
   content
 
  Even after applying the patch, the following psql variables were not
  displayed
  on the tab-completion of \set command.
 
  HISTFILE
  HISTSIZE
  HOST
  IGNOREEOF
  LASTOID
 
  I'm not sure if it's worth displaying all of them on the tab-completion
  of
  \set
  because it seems strange to change some of them by \set command, for
  example
  HOST, though.
 
 
  For these variables are not default - so doesn't exist and cannot be
  completed by default.
 
  there are two fix:
 
  a) fix autocomplete source - preferred

 +1


 here is the patch

Thanks for the patch!

I got the following compiler warnings.

tab-complete.c:4155: warning: assignment discards qualifiers from
pointer target type
tab-complete.c:4166: warning: assignment discards qualifiers from
pointer target type

+FETCH_COUNT, HISTCONTROL, HISTFILE, HISTSIZE, HOST,
IGNOREOFF,

Typo: IGNOREOFF - IGNOREEOF

+/* all psql known variables are included in list by default */
+for (known_varname = known_varnames; *known_varname; known_varname++)
+varnames[nvars++] = pg_strdup(*known_varname);

Don't we need to append both prefix and suffix to even known variables?

+else if (strcmp(prev2_wd, \\set) == 0)
+{
+if (strcmp(prev_wd, AUTOCOMMIT) == 0)

ISTM that some psql variables like IGNOREEOF are not there. 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


Re: [HACKERS] psql: show only failed queries

2014-07-15 Thread Fujii Masao
On Thu, Jul 10, 2014 at 9:56 PM, Pavel Stehule pavel.steh...@gmail.com wrote:
 Hello

 here is a proposed patch - autocomplete for known psql variable content

Even after applying the patch, the following psql variables were not displayed
on the tab-completion of \set command.

HISTFILE
HISTSIZE
HOST
IGNOREEOF
LASTOID

I'm not sure if it's worth displaying all of them on the tab-completion of \set
because it seems strange to change some of them by \set command, for example
HOST, though.

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


Re: [HACKERS] psql: show only failed queries

2014-07-15 Thread Pavel Stehule
2014-07-15 11:29 GMT+02:00 Fujii Masao masao.fu...@gmail.com:

 On Thu, Jul 10, 2014 at 9:56 PM, Pavel Stehule pavel.steh...@gmail.com
 wrote:
  Hello
 
  here is a proposed patch - autocomplete for known psql variable content

 Even after applying the patch, the following psql variables were not
 displayed
 on the tab-completion of \set command.

 HISTFILE
 HISTSIZE
 HOST
 IGNOREEOF
 LASTOID

 I'm not sure if it's worth displaying all of them on the tab-completion of
 \set
 because it seems strange to change some of them by \set command, for
 example
 HOST, though.


For these variables are not default - so doesn't exist and cannot be
completed by default.

there are two fix:

a) fix autocomplete source - preferred
b) create default - but it is probably impossible

Regards

Pavel



 Regards,

 --
 Fujii Masao



Re: [HACKERS] psql: show only failed queries

2014-07-15 Thread Fujii Masao
On Tue, Jul 15, 2014 at 7:01 PM, Pavel Stehule pavel.steh...@gmail.com wrote:



 2014-07-15 11:29 GMT+02:00 Fujii Masao masao.fu...@gmail.com:

 On Thu, Jul 10, 2014 at 9:56 PM, Pavel Stehule pavel.steh...@gmail.com
 wrote:
  Hello
 
  here is a proposed patch - autocomplete for known psql variable content

 Even after applying the patch, the following psql variables were not
 displayed
 on the tab-completion of \set command.

 HISTFILE
 HISTSIZE
 HOST
 IGNOREEOF
 LASTOID

 I'm not sure if it's worth displaying all of them on the tab-completion of
 \set
 because it seems strange to change some of them by \set command, for
 example
 HOST, though.


 For these variables are not default - so doesn't exist and cannot be
 completed by default.

 there are two fix:

 a) fix autocomplete source - preferred

+1

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


Re: [HACKERS] psql: show only failed queries

2014-07-15 Thread Pavel Stehule
2014-07-15 12:07 GMT+02:00 Fujii Masao masao.fu...@gmail.com:

 On Tue, Jul 15, 2014 at 7:01 PM, Pavel Stehule pavel.steh...@gmail.com
 wrote:
 
 
 
  2014-07-15 11:29 GMT+02:00 Fujii Masao masao.fu...@gmail.com:
 
  On Thu, Jul 10, 2014 at 9:56 PM, Pavel Stehule pavel.steh...@gmail.com
 
  wrote:
   Hello
  
   here is a proposed patch - autocomplete for known psql variable
 content
 
  Even after applying the patch, the following psql variables were not
  displayed
  on the tab-completion of \set command.
 
  HISTFILE
  HISTSIZE
  HOST
  IGNOREEOF
  LASTOID
 
  I'm not sure if it's worth displaying all of them on the tab-completion
 of
  \set
  because it seems strange to change some of them by \set command, for
  example
  HOST, though.
 
 
  For these variables are not default - so doesn't exist and cannot be
  completed by default.
 
  there are two fix:
 
  a) fix autocomplete source - preferred

 +1


here is the patch

Regards

Pavel





 Regards,

 --
 Fujii Masao

commit 1d0ef57d2774f37c464f25fe4e0d3be75bd36aeb
Author: root root@localhost.localdomain
Date:   Thu Jul 10 14:54:36 2014 +0200

all known psql variables are in list now

diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index bab0357..e45027e 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -3592,6 +3592,79 @@ psql_completion(const char *text, int start, int end)
 	{
 		matches = complete_from_variables(text, , );
 	}
+	else if (strcmp(prev2_wd, \\set) == 0)
+	{
+		if (strcmp(prev_wd, AUTOCOMMIT) == 0)
+		{
+			static const char *const my_list[] =
+			{on, off, interactive, NULL};
+
+			COMPLETE_WITH_LIST_CS(my_list);
+		}
+		else if (strcmp(prev_wd, COMP_KEYWORD_CASE) == 0)
+		{
+			static const char *const my_list[] =
+			{lower, upper, preserve-lower, preserve-upper, NULL};
+
+			COMPLETE_WITH_LIST_CS(my_list);
+		}
+		else if (strcmp(prev_wd, ECHO) == 0)
+		{
+			static const char *const my_list[] =
+			{none, errors, queries, all, NULL};
+
+			COMPLETE_WITH_LIST_CS(my_list);
+		}
+		else if (strcmp(prev_wd, ECHO_HIDDEN) == 0)
+		{
+			static const char *const my_list[] =
+			{noexec, off, on, NULL};
+
+			COMPLETE_WITH_LIST_CS(my_list);
+		}
+		else if (strcmp(prev_wd, ON_ERROR_ROLLBACK) == 0)
+		{
+			static const char *const my_list[] =
+			{on, off, interactive, NULL};
+
+			COMPLETE_WITH_LIST_CS(my_list);
+		}
+		else if (strcmp(prev_wd, ON_ERROR_STOP) == 0)
+		{
+			static const char *const my_list[] =
+			{on, off, NULL};
+
+			COMPLETE_WITH_LIST_CS(my_list);
+		}
+		else if (strcmp(prev_wd, QUIET) == 0)
+		{
+			static const char *const my_list[] =
+			{on, off, NULL};
+
+			COMPLETE_WITH_LIST_CS(my_list);
+		}
+		else if (strcmp(prev_wd, SINGLELINE) == 0)
+		{
+			static const char *const my_list[] =
+			{on, off, NULL};
+
+			COMPLETE_WITH_LIST_CS(my_list);
+		}
+		else if (strcmp(prev_wd, SINGLESTEP) == 0)
+		{
+			static const char *const my_list[] =
+			{on, off, NULL};
+
+			COMPLETE_WITH_LIST_CS(my_list);
+		}
+		else if (strcmp(prev_wd, VERBOSITY) == 0)
+		{
+			static const char *const my_list[] =
+			{default, verbose, terse, NULL};
+
+			COMPLETE_WITH_LIST_CS(my_list);
+		}
+	}
 	else if (strcmp(prev_wd, \\sf) == 0 || strcmp(prev_wd, \\sf+) == 0)
 		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_functions, NULL);
 	else if (strcmp(prev_wd, \\cd) == 0 ||
@@ -4046,28 +4119,61 @@ complete_from_variables(const char *text, const char *prefix, const char *suffix
 {
 	char	  **matches;
 	char	  **varnames;
+	static const char **known_varname;
 	int			nvars = 0;
 	int			maxvars = 100;
 	int			i;
 	struct _variable *ptr;
 
+	static const char *const known_varnames[] = {
+		AUTOCOMMIT, COMP_KEYWORD_CASE, DBNAME, ECHO, ECHO_HIDDEN, ENCODING,
+		FETCH_COUNT, HISTCONTROL, HISTFILE, HISTSIZE, HOST, IGNOREOFF,
+		LASTOID, ON_ERROR_ROLLBACK, ON_ERROR_STOP, PORT, PROMPT1, PROMPT2,
+		PROMPT3, QUIET, SINGLELINE, SINGLESTEP, USER, VERBOSITY,
+		NULL
+	};
+
 	varnames = (char **) pg_malloc((maxvars + 1) * sizeof(char *));
 
+	/* all psql known variables are included in list by default */
+	for (known_varname = known_varnames; *known_varname; known_varname++)
+		varnames[nvars++] = pg_strdup(*known_varname);
+
 	for (ptr = pset.vars-next; ptr; ptr = ptr-next)
 	{
-		if (nvars = maxvars)
+		char *varname;
+		bool is_known_varname = false;
+
+		varname = psprintf(%s%s%s, prefix, ptr-name, suffix);
+
+		/* is it known varname? */
+		for (known_varname = known_varnames; *known_varname; known_varname++)
 		{
-			maxvars *= 2;
-			varnames = (char **) realloc(varnames,
-		 (maxvars + 1) * sizeof(char *));
-			if (!varnames)
+			if (strcmp(*known_varname, varname) == 0)
 			{
-psql_error(out of memory\n);
-exit(EXIT_FAILURE);
+free(varname);
+is_known_varname = true;
+break;
 			}
 		}
 
-		varnames[nvars++] = psprintf(%s%s%s, prefix, ptr-name, suffix);
+		/* append only unknown varnames, known varnames are in list already */
+		if (!is_known_varname)
+		{
+			

Re: [HACKERS] psql: show only failed queries

2014-07-10 Thread Pavel Stehule
2014-07-10 7:32 GMT+02:00 Fujii Masao masao.fu...@gmail.com:

 On Wed, Jul 9, 2014 at 9:44 PM, Pavel Stehule pavel.steh...@gmail.com
 wrote:
  Barring any objection, I will commit this patch except tab-completion
  part.

 Committed.


Thank you very much


  It can be a second discussion, but I am thinking so anywhere when we can
 use
  autocomplete, then we should it - Although it should not to substitute
  documentation, it is fast help about available options, mainly in
 situation
  where variables can hold a relative different content. I can prepare, if
  there will not any objection addition patch with complete autocomplete
 for
  all psql variables described in doc.

 I have no objection. But I found that the tab-completion for psql
 variables names
 are not complete. For example, COMP_KEYWORD_CASE is not displayed.
 Probably we should address this problem, too.


I prepare patch for next commitfest - it is relative trivial task

Pavel



 Regards,

 --
 Fujii Masao



Re: [HACKERS] psql: show only failed queries

2014-07-10 Thread Pavel Stehule
Hello

here is a proposed patch - autocomplete for known psql variable content

Regards

Pavel


2014-07-10 9:50 GMT+02:00 Pavel Stehule pavel.steh...@gmail.com:




 2014-07-10 7:32 GMT+02:00 Fujii Masao masao.fu...@gmail.com:

 On Wed, Jul 9, 2014 at 9:44 PM, Pavel Stehule pavel.steh...@gmail.com
 wrote:
  Barring any objection, I will commit this patch except tab-completion
  part.

 Committed.


 Thank you very much


  It can be a second discussion, but I am thinking so anywhere when we
 can use
  autocomplete, then we should it - Although it should not to substitute
  documentation, it is fast help about available options, mainly in
 situation
  where variables can hold a relative different content. I can prepare, if
  there will not any objection addition patch with complete autocomplete
 for
  all psql variables described in doc.

 I have no objection. But I found that the tab-completion for psql
 variables names
 are not complete. For example, COMP_KEYWORD_CASE is not displayed.
 Probably we should address this problem, too.


 I prepare patch for next commitfest - it is relative trivial task

 Pavel



 Regards,

 --
 Fujii Masao



commit 7cba776aea228165c5b65f7077515328a0efa039
Author: root root@localhost.localdomain
Date:   Thu Jul 10 14:54:36 2014 +0200

initial concept

diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c
index 5a397e8..f05dfe2 100644
--- a/src/bin/psql/startup.c
+++ b/src/bin/psql/startup.c
@@ -147,6 +147,8 @@ main(int argc, char *argv[])
 	SetVariable(pset.vars, PROMPT2, DEFAULT_PROMPT2);
 	SetVariable(pset.vars, PROMPT3, DEFAULT_PROMPT3);
 
+	SetVariable(pset.vars, COMP_KEYWORD_CASE, preserve-upper);
+
 	parse_psql_options(argc, argv, options);
 
 	/*
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index bab0357..41ae499 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -3592,6 +3592,79 @@ psql_completion(const char *text, int start, int end)
 	{
 		matches = complete_from_variables(text, , );
 	}
+	else if (strcmp(prev2_wd, \\set) == 0)
+	{
+		if (strcmp(prev_wd, AUTOCOMMIT) == 0)
+		{
+			static const char *const my_list[] =
+			{on, off, interactive, NULL};
+
+			COMPLETE_WITH_LIST_CS(my_list);
+		}
+		else if (strcmp(prev_wd, COMP_KEYWORD_CASE) == 0)
+		{
+			static const char *const my_list[] =
+			{lower, upper, preserve-lower, preserve-upper, NULL};
+
+			COMPLETE_WITH_LIST_CS(my_list);
+		}
+		else if (strcmp(prev_wd, ECHO) == 0)
+		{
+			static const char *const my_list[] =
+			{none, errors, queries, all, NULL};
+
+			COMPLETE_WITH_LIST_CS(my_list);
+		}
+		else if (strcmp(prev_wd, ECHO_HIDDEN) == 0)
+		{
+			static const char *const my_list[] =
+			{noexec, off, on, NULL};
+
+			COMPLETE_WITH_LIST_CS(my_list);
+		}
+		else if (strcmp(prev_wd, ON_ERROR_ROLLBACK) == 0)
+		{
+			static const char *const my_list[] =
+			{on, off, interactive, NULL};
+
+			COMPLETE_WITH_LIST_CS(my_list);
+		}
+		else if (strcmp(prev_wd, ON_ERROR_STOP) == 0)
+		{
+			static const char *const my_list[] =
+			{on, off, NULL};
+
+			COMPLETE_WITH_LIST_CS(my_list);
+		}
+		else if (strcmp(prev_wd, QUIET) == 0)
+		{
+			static const char *const my_list[] =
+			{on, off, NULL};
+
+			COMPLETE_WITH_LIST_CS(my_list);
+		}
+		else if (strcmp(prev_wd, SINGLELINE) == 0)
+		{
+			static const char *const my_list[] =
+			{on, off, NULL};
+
+			COMPLETE_WITH_LIST_CS(my_list);
+		}
+		else if (strcmp(prev_wd, SINGLESTEP) == 0)
+		{
+			static const char *const my_list[] =
+			{on, off, NULL};
+
+			COMPLETE_WITH_LIST_CS(my_list);
+		}
+		else if (strcmp(prev_wd, VERBOSITY) == 0)
+		{
+			static const char *const my_list[] =
+			{default, verbose, terse, NULL};
+
+			COMPLETE_WITH_LIST_CS(my_list);
+		}
+	}
 	else if (strcmp(prev_wd, \\sf) == 0 || strcmp(prev_wd, \\sf+) == 0)
 		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_functions, NULL);
 	else if (strcmp(prev_wd, \\cd) == 0 ||

-- 
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: show only failed queries

2014-07-09 Thread Pavel Stehule
Hi


2014-07-09 7:07 GMT+02:00 Fujii Masao masao.fu...@gmail.com:

 On Mon, Jun 30, 2014 at 8:33 PM, Pavel Stehule pavel.steh...@gmail.com
 wrote:
 
 
 
  2014-06-30 13:01 GMT+02:00 Abhijit Menon-Sen a...@2ndquadrant.com:
 
  At 2014-06-30 12:48:30 +0200, pavel.steh...@gmail.com wrote:
  
   +  para
   +  Print a failed SQL commands to standard error output. This is
   +  equivalent to setting the variable varnameECHO/varname to
   +  literalerrors/literal.
 
  No a, just Print failed SQL commands ….
 
   -option-e/option.
   +option-e/option. If set to literalerror/literal then
   only
   +failed queries are displayed.
 
  Should be errors here, not error.
 
 printf(_(  -a, --echo-all   echo all input from
   script\n));
   + printf(_(  -b  --echo-errorsecho failed commands sent
 to
   server\n));
 printf(_(  -e, --echo-queries   echo commands sent to
   server\n));
 
  Should have a comma after -b to match other options. Also I would remove
  sent to server from the description: echo failed commands is fine.
 
 
  fixed

 $ psql -b
 bin/psql: invalid option -- 'b'
 Try psql --help for more information.

 I got this error. ISTM you forgot to add 'b' into the third argument of
 getopt_long in startup.c.


fixed


  applicationpsql/application merely prints all queries as
  they are sent to the server. The switch for this is
 -option-e/option.
 +option-e/option. If set to literalerrors/literal then only
 +failed queries are displayed.

 I think that where failed queries are output should be documented here.
 Otherwise users might misunderstand they are output to standard output
 like ECHO=all and queries do.

 It's better to add The switch for this is option-b/option. into the
 doc.


fixed


 +else if (strcmp(prev2_wd, \\set) == 0)
 +{
 +if (strcmp(prev_wd, ECHO) == 0)
 +{
 +static const char *const my_list[] =
 +{none, errors, queries, all, NULL};
 +
 +COMPLETE_WITH_LIST_CS(my_list);
 +}
 +else if (strcmp(prev_wd, ECHO_HIDDEN) == 0)
 +{
 +static const char *const my_list[] =
 +{noexec, off, on, NULL};
 +
 +COMPLETE_WITH_LIST_CS(my_list);
 +}
 +}

 I think that adding tab-completions of psql variables is good, but
 adding those of only ECHO and ECHO_HIDDEN seems half-baked.
 Probably this part should be split into separate patch.


fixed

please, see updated patch in attachment

Thank you

Regards

Pavel



 Regards,

 --
 Fujii Masao

commit a05543802d000b3e66276b5ff370787d6f5ee7e3
Author: Pavel Stehule pavel.steh...@gooddata.com
Date:   Wed Jul 9 14:03:42 2014 +0200

version 04

diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index 255e8ca..bbe5935 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -73,6 +73,18 @@ PostgreSQL documentation
 /varlistentry
 
 varlistentry
+  termoption-b//term
+  termoption--echo-errors//term
+  listitem
+  para
+  Print failed SQL commands to standard error output. This is
+  equivalent to setting the variable varnameECHO/varname to
+  literalerrors/literal.
+  /para
+  /listitem
+/varlistentry
+
+varlistentry
   termoption-c replaceable class=parametercommand/replaceable//term
   termoption--command=replaceable class=parametercommand/replaceable//term
   listitem
@@ -2812,7 +2824,9 @@ bar
 literalqueries/literal,
 applicationpsql/application merely prints all queries as
 they are sent to the server. The switch for this is
-option-e/option.
+option-e/option. If set to literalerrors/literal then only
+failed queries are displayed on standard error output. The switch
+for this is option-b/option.
 /para
 /listitem
   /varlistentry
diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c
index c08c813..676e268 100644
--- a/src/bin/psql/common.c
+++ b/src/bin/psql/common.c
@@ -995,6 +995,9 @@ SendQuery(const char *query)
 		results = NULL;			/* PQclear(NULL) does nothing */
 	}
 
+	if (!OK  pset.echo == PSQL_ECHO_ERRORS)
+		psql_error(STATEMENT:  %s\n, query);
+
 	/* If we made a temporary savepoint, possibly release/rollback */
 	if (on_error_rollback_savepoint)
 	{
diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c
index 3aa3c16..f8f000f 100644
--- a/src/bin/psql/help.c
+++ b/src/bin/psql/help.c
@@ -87,6 +87,7 @@ usage(void)
 
 	printf(_(\nInput and output options:\n));
 	printf(_(  -a, --echo-all   echo all input from script\n));
+	printf(_(  -b, --echo-errorsecho failed commands\n));
 	printf(_(  -e, --echo-queries   echo commands sent to server\n));
 	printf(_(  -E, --echo-hiddendisplay queries that internal commands generate\n));
 	printf(_(  -L, --log-file=FILENAME  send session log to 

Re: [HACKERS] psql: show only failed queries

2014-07-09 Thread Fujii Masao
On Wed, Jul 9, 2014 at 9:06 PM, Pavel Stehule pavel.steh...@gmail.com wrote:
 Hi


 2014-07-09 7:07 GMT+02:00 Fujii Masao masao.fu...@gmail.com:

 On Mon, Jun 30, 2014 at 8:33 PM, Pavel Stehule pavel.steh...@gmail.com
 wrote:
 
 
 
  2014-06-30 13:01 GMT+02:00 Abhijit Menon-Sen a...@2ndquadrant.com:
 
  At 2014-06-30 12:48:30 +0200, pavel.steh...@gmail.com wrote:
  
   +  para
   +  Print a failed SQL commands to standard error output. This is
   +  equivalent to setting the variable varnameECHO/varname to
   +  literalerrors/literal.
 
  No a, just Print failed SQL commands ….
 
   -option-e/option.
   +option-e/option. If set to literalerror/literal then
   only
   +failed queries are displayed.
 
  Should be errors here, not error.
 
 printf(_(  -a, --echo-all   echo all input from
   script\n));
   + printf(_(  -b  --echo-errorsecho failed commands sent
   to
   server\n));
 printf(_(  -e, --echo-queries   echo commands sent to
   server\n));
 
  Should have a comma after -b to match other options. Also I would
  remove
  sent to server from the description: echo failed commands is fine.
 
 
  fixed

 $ psql -b
 bin/psql: invalid option -- 'b'
 Try psql --help for more information.

 I got this error. ISTM you forgot to add 'b' into the third argument of
 getopt_long in startup.c.


 fixed


  applicationpsql/application merely prints all queries as
  they are sent to the server. The switch for this is
 -option-e/option.
 +option-e/option. If set to literalerrors/literal then
 only
 +failed queries are displayed.

 I think that where failed queries are output should be documented here.
 Otherwise users might misunderstand they are output to standard output
 like ECHO=all and queries do.

 It's better to add The switch for this is option-b/option. into the
 doc.


 fixed


 +else if (strcmp(prev2_wd, \\set) == 0)
 +{
 +if (strcmp(prev_wd, ECHO) == 0)
 +{
 +static const char *const my_list[] =
 +{none, errors, queries, all, NULL};
 +
 +COMPLETE_WITH_LIST_CS(my_list);
 +}
 +else if (strcmp(prev_wd, ECHO_HIDDEN) == 0)
 +{
 +static const char *const my_list[] =
 +{noexec, off, on, NULL};
 +
 +COMPLETE_WITH_LIST_CS(my_list);
 +}
 +}

 I think that adding tab-completions of psql variables is good, but
 adding those of only ECHO and ECHO_HIDDEN seems half-baked.
 Probably this part should be split into separate patch.


 fixed

 please, see updated patch in attachment

Thanks for updating the patch!

Barring any objection, I will commit this patch except tab-completion part.

I'm not against adding tab-completion support for psql variables, but I'm
not sure if it's good idea or not to treat only one or two variables special
and add tab-completions for them. There are other variables which accept
special argument (e.g., COMP_KEYWORD_CASE) and it's basically worth
adding tab-completion support for them.

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


Re: [HACKERS] psql: show only failed queries

2014-07-09 Thread Pavel Stehule
2014-07-09 14:39 GMT+02:00 Fujii Masao masao.fu...@gmail.com:

 On Wed, Jul 9, 2014 at 9:06 PM, Pavel Stehule pavel.steh...@gmail.com
 wrote:
  Hi
 
 
  2014-07-09 7:07 GMT+02:00 Fujii Masao masao.fu...@gmail.com:
 
  On Mon, Jun 30, 2014 at 8:33 PM, Pavel Stehule pavel.steh...@gmail.com
 
  wrote:
  
  
  
   2014-06-30 13:01 GMT+02:00 Abhijit Menon-Sen a...@2ndquadrant.com:
  
   At 2014-06-30 12:48:30 +0200, pavel.steh...@gmail.com wrote:
   
+  para
+  Print a failed SQL commands to standard error output. This
 is
+  equivalent to setting the variable varnameECHO/varname
 to
+  literalerrors/literal.
  
   No a, just Print failed SQL commands ….
  
-option-e/option.
+option-e/option. If set to literalerror/literal
 then
only
+failed queries are displayed.
  
   Should be errors here, not error.
  
  printf(_(  -a, --echo-all   echo all input from
script\n));
+ printf(_(  -b  --echo-errorsecho failed commands
 sent
to
server\n));
  printf(_(  -e, --echo-queries   echo commands sent to
server\n));
  
   Should have a comma after -b to match other options. Also I would
   remove
   sent to server from the description: echo failed commands is
 fine.
  
  
   fixed
 
  $ psql -b
  bin/psql: invalid option -- 'b'
  Try psql --help for more information.
 
  I got this error. ISTM you forgot to add 'b' into the third argument of
  getopt_long in startup.c.
 
 
  fixed
 
 
   applicationpsql/application merely prints all queries as
   they are sent to the server. The switch for this is
  -option-e/option.
  +option-e/option. If set to literalerrors/literal then
  only
  +failed queries are displayed.
 
  I think that where failed queries are output should be documented here.
  Otherwise users might misunderstand they are output to standard output
  like ECHO=all and queries do.
 
  It's better to add The switch for this is option-b/option. into
 the
  doc.
 
 
  fixed
 
 
  +else if (strcmp(prev2_wd, \\set) == 0)
  +{
  +if (strcmp(prev_wd, ECHO) == 0)
  +{
  +static const char *const my_list[] =
  +{none, errors, queries, all, NULL};
  +
  +COMPLETE_WITH_LIST_CS(my_list);
  +}
  +else if (strcmp(prev_wd, ECHO_HIDDEN) == 0)
  +{
  +static const char *const my_list[] =
  +{noexec, off, on, NULL};
  +
  +COMPLETE_WITH_LIST_CS(my_list);
  +}
  +}
 
  I think that adding tab-completions of psql variables is good, but
  adding those of only ECHO and ECHO_HIDDEN seems half-baked.
  Probably this part should be split into separate patch.
 
 
  fixed
 
  please, see updated patch in attachment

 Thanks for updating the patch!

 Barring any objection, I will commit this patch except tab-completion part.


Thank you


 I'm not against adding tab-completion support for psql variables, but I'm
 not sure if it's good idea or not to treat only one or two variables
 special
 and add tab-completions for them. There are other variables which accept
 special argument (e.g., COMP_KEYWORD_CASE) and it's basically worth
 adding tab-completion support for them.



It can be a second discussion, but I am thinking so anywhere when we can
use autocomplete, then we should it - Although it should not to substitute
documentation, it is fast help about available options, mainly in situation
where variables can hold a relative different content. I can prepare, if
there will not any objection addition patch with complete autocomplete for
all psql variables described in doc.

Regards

Pavel



 Regards,

 --
 Fujii Masao



Re: [HACKERS] psql: show only failed queries

2014-07-09 Thread Fujii Masao
On Wed, Jul 9, 2014 at 9:44 PM, Pavel Stehule pavel.steh...@gmail.com wrote:
 Barring any objection, I will commit this patch except tab-completion
 part.

Committed.

 It can be a second discussion, but I am thinking so anywhere when we can use
 autocomplete, then we should it - Although it should not to substitute
 documentation, it is fast help about available options, mainly in situation
 where variables can hold a relative different content. I can prepare, if
 there will not any objection addition patch with complete autocomplete for
 all psql variables described in doc.

I have no objection. But I found that the tab-completion for psql
variables names
are not complete. For example, COMP_KEYWORD_CASE is not displayed.
Probably we should address this problem, too.

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


Re: [HACKERS] psql: show only failed queries

2014-07-08 Thread Fujii Masao
On Mon, Jun 30, 2014 at 8:33 PM, Pavel Stehule pavel.steh...@gmail.com wrote:



 2014-06-30 13:01 GMT+02:00 Abhijit Menon-Sen a...@2ndquadrant.com:

 At 2014-06-30 12:48:30 +0200, pavel.steh...@gmail.com wrote:
 
  +  para
  +  Print a failed SQL commands to standard error output. This is
  +  equivalent to setting the variable varnameECHO/varname to
  +  literalerrors/literal.

 No a, just Print failed SQL commands ….

  -option-e/option.
  +option-e/option. If set to literalerror/literal then
  only
  +failed queries are displayed.

 Should be errors here, not error.

printf(_(  -a, --echo-all   echo all input from
  script\n));
  + printf(_(  -b  --echo-errorsecho failed commands sent to
  server\n));
printf(_(  -e, --echo-queries   echo commands sent to
  server\n));

 Should have a comma after -b to match other options. Also I would remove
 sent to server from the description: echo failed commands is fine.


 fixed

$ psql -b
bin/psql: invalid option -- 'b'
Try psql --help for more information.

I got this error. ISTM you forgot to add 'b' into the third argument of
getopt_long in startup.c.

 applicationpsql/application merely prints all queries as
 they are sent to the server. The switch for this is
-option-e/option.
+option-e/option. If set to literalerrors/literal then only
+failed queries are displayed.

I think that where failed queries are output should be documented here.
Otherwise users might misunderstand they are output to standard output
like ECHO=all and queries do.

It's better to add The switch for this is option-b/option. into the doc.

+else if (strcmp(prev2_wd, \\set) == 0)
+{
+if (strcmp(prev_wd, ECHO) == 0)
+{
+static const char *const my_list[] =
+{none, errors, queries, all, NULL};
+
+COMPLETE_WITH_LIST_CS(my_list);
+}
+else if (strcmp(prev_wd, ECHO_HIDDEN) == 0)
+{
+static const char *const my_list[] =
+{noexec, off, on, NULL};
+
+COMPLETE_WITH_LIST_CS(my_list);
+}
+}

I think that adding tab-completions of psql variables is good, but
adding those of only ECHO and ECHO_HIDDEN seems half-baked.
Probably this part should be split into separate patch.

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


Re: [HACKERS] psql: show only failed queries

2014-06-30 Thread Rajeev rastogi
On 26 June 2014 11:53, Samrat Revagade Wrote:

 I am sending updated patch - buggy statement is printed via more logical 
 psql_error function instead printf

Thank you for updating patch, I really appreciate your efforts.

Now, everything is good from my side.
* it apply cleanly to the current git master
* includes necessary docs
* I think It is very good  and necessary feature.

If Kumar Rajeev Rastogi do not have any extra comments, then I think patch is  
ready for committer.

I have reviewed this patch. Please find my review comments below:

1. Command start-up option (e.g. -a/--echo-all for --ECHO=all), for new 
functionality is not provided.

2. New Command start-up option should be added in psql --help as well as 
in documentation.

Also as I understand, this new option is kind of sub-set of existing option 
(ECHO=query), so should not we display
query string in the same format as it was getting printed earlier.
Though I also feel that prefixing query with STATEMENT word will be helpful to 
grep but at the same time I am worried
about inconsistency with existing option.

Thanks and Regards,
Kumar Rajeev Rastogi


Re: [HACKERS] psql: show only failed queries

2014-06-30 Thread Pavel Stehule
2014-06-30 8:17 GMT+02:00 Rajeev rastogi rajeev.rast...@huawei.com:

  On 26 June 2014 11:53, Samrat Revagade Wrote:



  I am sending updated patch - buggy statement is printed via more
 logical psql_error function instead printf



 Thank you for updating patch, I really appreciate your efforts.



 Now, everything is good from my side.

 * it apply cleanly to the current git master

 * includes necessary docs

 * I think It is very good  and necessary feature.



 If Kumar Rajeev Rastogi do not have any extra comments, then I
 think patch is  ready for committer.



 I have reviewed this patch. Please find my review comments below:

 1. Command start-up option (e.g. -a/--echo-all for --ECHO=all), for
 new functionality is not provided.

all not options entered via psql variables has psql option and psql
comment. I'll plan add new decription to --help-variables list.

If it is necessary I can add long option --echo-errors, I didn't a good
char for short option. Any idea?




  2. New Command start-up option should be added in psql --help as
 well as in documentation.

depends on previous,





 Also as I understand, this new option is kind of sub-set of existing
 option (ECHO=query), so should not we display

 query string in the same format as it was getting printed earlier.

 Though I also feel that prefixing query with STATEMENT word will be
 helpful to grep but at the same time I am worried

 about inconsistency with existing option.


This is question. And I am not strong in feeling what should be preferred.
But still I am inclined to prefer a variant with STATEMENT prefix. Mode
with -a is used with different purpose than mode show errors only - and
output with prefix is much more consistent with log entry - and displaying
error. So I agree, so there is potential inconsistency (but nowhere is
output defined), but this output is more practical, when you are
concentrated to error's processing.

Regards

Pavel




 *Thanks and Regards,*

 *Kumar Rajeev Rastogi *



Re: [HACKERS] psql: show only failed queries

2014-06-30 Thread Rajeev rastogi
On 30 June 2014 12:24, Pavel Stehule Wrote:

I have reviewed this patch. Please find my review comments below:

1. Command start-up option (e.g. -a/--echo-all for --ECHO=all), for new 
functionality is not provided.
all not options entered via psql variables has psql option and psql comment. 
I'll plan add new decription to --help-variables list.
If it is necessary I can add long option --echo-errors, I didn't a good char 
for short option. Any idea?

But the new option we are adding are on a track of existing option, so better 
we add start-up option for this also.
Yeah long option –echo-errors seems to be fine to me also. For short option, I 
think we can use “-b” stands for blunder. This is the closest one I could think 
of.


2. New Command start-up option should be added in psql --help as well 
as in documentation.
depends on previous,
Right.
Also as I understand, this new option is kind of sub-set of existing option 
(ECHO=query), so should not we display
query string in the same format as it was getting printed earlier.
Though I also feel that prefixing query with STATEMENT word will be helpful 
to grep but at the same time I am worried
about inconsistency with existing option.

This is question. And I am not strong in feeling what should be preferred. But 
still I am inclined to prefer a variant with STATEMENT prefix. Mode with -a is 
used with different purpose than mode show errors only - and output with 
prefix is much
 more consistent with log entry - and displaying error. So I agree, so there 
 is potential inconsistency (but nowhere is output defined), but this output 
 is more practical, when you are concentrated to error's processing.
Yeah right, I just wanted to raise point to provoke other thought to see if 
anyone having different opinion. If no objection from others, we can go ahead 
with the current prefixing approach.
Thanks and Regards,
Kumar Rajeev Rastogi


Re: [HACKERS] psql: show only failed queries

2014-06-30 Thread Pavel Stehule
2014-06-30 11:20 GMT+02:00 Rajeev rastogi rajeev.rast...@huawei.com:

  On 30 June 2014 12:24, Pavel Stehule Wrote:



 I have reviewed this patch. Please find my review comments below:

 1. Command start-up option (e.g. -a/--echo-all for --ECHO=all), for
 new functionality is not provided.

 all not options entered via psql variables has psql option and psql
 comment. I'll plan add new decription to --help-variables list.

 If it is necessary I can add long option --echo-errors, I didn't a good
 char for short option. Any idea?



 But the new option we are adding are on a track of existing option, so
 better we add start-up option for this also.

 Yeah long option –echo-errors seems to be fine to me also. For short
 option, I think we can use “-b” stands for blunder. This is the closest one
 I could think of.


fixed

see a attachment pls




 2. New Command start-up option should be added in psql --help as
 well as in documentation.

 depends on previous,

 Right.

 Also as I understand, this new option is kind of sub-set of existing
 option (ECHO=query), so should not we display

 query string in the same format as it was getting printed earlier.

 Though I also feel that prefixing query with STATEMENT word will be
 helpful to grep but at the same time I am worried

 about inconsistency with existing option.



 This is question. And I am not strong in feeling what should be
 preferred. But still I am inclined to prefer a variant with STATEMENT
 prefix. Mode with -a is used with different purpose than mode show errors
 only - and output with prefix is much

  more consistent with log entry - and displaying error. So I agree, so
 there is potential inconsistency (but nowhere is output defined), but this
 output is more practical, when you are concentrated to error's processing.

 Yeah right, I just wanted to raise point to provoke other thought to see
 if anyone having different opinion. If no objection from others, we can go
 ahead with the current prefixing approach.

ok, we can wait two days

Regards

Pavel





  *Thanks and Regards,*

 *Kumar Rajeev Rastogi*

commit e05f23c69db53cefa0c3438c5eaeec11e5fa05b0
Author: Pavel Stehule pavel.steh...@gooddata.com
Date:   Mon Jun 30 12:39:42 2014 +0200

new -b, --echo-errors option

diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index ee6ec3a..ccaf1c3 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -73,6 +73,18 @@ PostgreSQL documentation
 /varlistentry
 
 varlistentry
+  termoption-b//term
+  termoption--echo-errors//term
+  listitem
+  para
+  Print a failed SQL commands to standard error output. This is
+  equivalent to setting the variable varnameECHO/varname to
+  literalerrors/literal.
+  /para
+  /listitem
+/varlistentry
+
+varlistentry
   termoption-c replaceable class=parametercommand/replaceable//term
   termoption--command=replaceable class=parametercommand/replaceable//term
   listitem
@@ -2812,7 +2824,8 @@ bar
 literalqueries/literal,
 applicationpsql/application merely prints all queries as
 they are sent to the server. The switch for this is
-option-e/option.
+option-e/option. If set to literalerror/literal then only
+failed queries are displayed.
 /para
 /listitem
   /varlistentry
diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c
index 60169a2..6551b15 100644
--- a/src/bin/psql/common.c
+++ b/src/bin/psql/common.c
@@ -995,6 +995,9 @@ SendQuery(const char *query)
 		results = NULL;			/* PQclear(NULL) does nothing */
 	}
 
+	if (!OK  pset.echo == PSQL_ECHO_ERRORS)
+		psql_error(STATEMENT:  %s\n, query);
+
 	/* If we made a temporary savepoint, possibly release/rollback */
 	if (on_error_rollback_savepoint)
 	{
diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c
index 3aa3c16..0128060 100644
--- a/src/bin/psql/help.c
+++ b/src/bin/psql/help.c
@@ -87,6 +87,7 @@ usage(void)
 
 	printf(_(\nInput and output options:\n));
 	printf(_(  -a, --echo-all   echo all input from script\n));
+	printf(_(  -b  --echo-errorsecho failed commands sent to server\n));
 	printf(_(  -e, --echo-queries   echo commands sent to server\n));
 	printf(_(  -E, --echo-hiddendisplay queries that internal commands generate\n));
 	printf(_(  -L, --log-file=FILENAME  send session log to file\n));
diff --git a/src/bin/psql/settings.h b/src/bin/psql/settings.h
index 0a60e68..453d6c8 100644
--- a/src/bin/psql/settings.h
+++ b/src/bin/psql/settings.h
@@ -31,6 +31,7 @@ typedef enum
 {
 	PSQL_ECHO_NONE,
 	PSQL_ECHO_QUERIES,
+	PSQL_ECHO_ERRORS,
 	PSQL_ECHO_ALL
 } PSQL_ECHO;
 
diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c
index 45653a1..3ca3f1e 100644
--- a/src/bin/psql/startup.c
+++ b/src/bin/psql/startup.c
@@ -354,6 +354,7 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
 		{command, 

Re: [HACKERS] psql: show only failed queries

2014-06-30 Thread Abhijit Menon-Sen
At 2014-06-30 12:48:30 +0200, pavel.steh...@gmail.com wrote:

 +  para
 +  Print a failed SQL commands to standard error output. This is
 +  equivalent to setting the variable varnameECHO/varname to
 +  literalerrors/literal.

No a, just Print failed SQL commands ….

 -option-e/option.
 +option-e/option. If set to literalerror/literal then only
 +failed queries are displayed.

Should be errors here, not error.

   printf(_(  -a, --echo-all   echo all input from script\n));
 + printf(_(  -b  --echo-errorsecho failed commands sent to 
 server\n));
   printf(_(  -e, --echo-queries   echo commands sent to server\n));

Should have a comma after -b to match other options. Also I would remove
sent to server from the description: echo failed commands is fine.

Otherwise looks fine. I see no reason to wait for further feedback, so
I'll mark this ready for committer if you make the above corrections.

At some point, you should probably also update your --help-variables
patch to add this new value to the description of ECHO.

-- Abhijit


-- 
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: show only failed queries

2014-06-30 Thread Pavel Stehule
2014-06-30 13:01 GMT+02:00 Abhijit Menon-Sen a...@2ndquadrant.com:

 At 2014-06-30 12:48:30 +0200, pavel.steh...@gmail.com wrote:
 
  +  para
  +  Print a failed SQL commands to standard error output. This is
  +  equivalent to setting the variable varnameECHO/varname to
  +  literalerrors/literal.

 No a, just Print failed SQL commands ….

  -option-e/option.
  +option-e/option. If set to literalerror/literal then
 only
  +failed queries are displayed.

 Should be errors here, not error.

printf(_(  -a, --echo-all   echo all input from
 script\n));
  + printf(_(  -b  --echo-errorsecho failed commands sent to
 server\n));
printf(_(  -e, --echo-queries   echo commands sent to
 server\n));

 Should have a comma after -b to match other options. Also I would remove
 sent to server from the description: echo failed commands is fine.


fixed



 Otherwise looks fine. I see no reason to wait for further feedback, so
 I'll mark this ready for committer if you make the above corrections.

 At some point, you should probably also update your --help-variables
 patch to add this new value to the description of ECHO.


I have it in TODO. But I don't would to introduce a dependency between
these patches - so when first patch will be committed, than I update second
patch

Regards

Pavel



 -- Abhijit

commit 998203a2e35643430059c4d3490a176a830cfee2
Author: Pavel Stehule pavel.steh...@gooddata.com
Date:   Mon Jun 30 12:39:42 2014 +0200

new -b, --echo-errors option

diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index ee6ec3a..2c4cc96 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -73,6 +73,18 @@ PostgreSQL documentation
 /varlistentry
 
 varlistentry
+  termoption-b//term
+  termoption--echo-errors//term
+  listitem
+  para
+  Print failed SQL commands to standard error output. This is
+  equivalent to setting the variable varnameECHO/varname to
+  literalerrors/literal.
+  /para
+  /listitem
+/varlistentry
+
+varlistentry
   termoption-c replaceable class=parametercommand/replaceable//term
   termoption--command=replaceable class=parametercommand/replaceable//term
   listitem
@@ -2812,7 +2824,8 @@ bar
 literalqueries/literal,
 applicationpsql/application merely prints all queries as
 they are sent to the server. The switch for this is
-option-e/option.
+option-e/option. If set to literalerrors/literal then only
+failed queries are displayed.
 /para
 /listitem
   /varlistentry
diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c
index 60169a2..6551b15 100644
--- a/src/bin/psql/common.c
+++ b/src/bin/psql/common.c
@@ -995,6 +995,9 @@ SendQuery(const char *query)
 		results = NULL;			/* PQclear(NULL) does nothing */
 	}
 
+	if (!OK  pset.echo == PSQL_ECHO_ERRORS)
+		psql_error(STATEMENT:  %s\n, query);
+
 	/* If we made a temporary savepoint, possibly release/rollback */
 	if (on_error_rollback_savepoint)
 	{
diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c
index 3aa3c16..f8f000f 100644
--- a/src/bin/psql/help.c
+++ b/src/bin/psql/help.c
@@ -87,6 +87,7 @@ usage(void)
 
 	printf(_(\nInput and output options:\n));
 	printf(_(  -a, --echo-all   echo all input from script\n));
+	printf(_(  -b, --echo-errorsecho failed commands\n));
 	printf(_(  -e, --echo-queries   echo commands sent to server\n));
 	printf(_(  -E, --echo-hiddendisplay queries that internal commands generate\n));
 	printf(_(  -L, --log-file=FILENAME  send session log to file\n));
diff --git a/src/bin/psql/settings.h b/src/bin/psql/settings.h
index 0a60e68..453d6c8 100644
--- a/src/bin/psql/settings.h
+++ b/src/bin/psql/settings.h
@@ -31,6 +31,7 @@ typedef enum
 {
 	PSQL_ECHO_NONE,
 	PSQL_ECHO_QUERIES,
+	PSQL_ECHO_ERRORS,
 	PSQL_ECHO_ALL
 } PSQL_ECHO;
 
diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c
index 45653a1..3ca3f1e 100644
--- a/src/bin/psql/startup.c
+++ b/src/bin/psql/startup.c
@@ -354,6 +354,7 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
 		{command, required_argument, NULL, 'c'},
 		{dbname, required_argument, NULL, 'd'},
 		{echo-queries, no_argument, NULL, 'e'},
+		{echo-errors, no_argument, NULL, 'b'},
 		{echo-hidden, no_argument, NULL, 'E'},
 		{file, required_argument, NULL, 'f'},
 		{field-separator, required_argument, NULL, 'F'},
@@ -402,6 +403,9 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
 			case 'A':
 pset.popt.topt.format = PRINT_UNALIGNED;
 break;
+			case 'b':
+SetVariable(pset.vars, ECHO, errors);
+break;
 			case 'c':
 options-action_string = pg_strdup(optarg);
 if (optarg[0] == '\\')
@@ -720,6 +724,8 @@ echo_hook(const char *newval)
 		pset.echo = PSQL_ECHO_NONE;
 	else if (strcmp(newval, queries) == 0)
 		pset.echo = 

Re: [HACKERS] psql: show only failed queries

2014-06-26 Thread Samrat Revagade
 I am sending updated patch - buggy statement is printed via more logical
psql_error function instead printf

Thank you for updating patch, I really appreciate your efforts.

Now, everything is good from my side.
* it apply cleanly to the current git master
* includes necessary docs
* I think It is very good  and necessary feature.

If Kumar Rajeev Rastogi do not have any extra comments, then I think patch
is  ready for committer.


Re: [HACKERS] psql: show only failed queries

2014-06-26 Thread Pavel Stehule
2014-06-26 8:22 GMT+02:00 Samrat Revagade revagade.sam...@gmail.com:

  I am sending updated patch - buggy statement is printed via more logical
 psql_error function instead printf

 Thank you for updating patch, I really appreciate your efforts.

 Now, everything is good from my side.
 * it apply cleanly to the current git master
 * includes necessary docs
 * I think It is very good  and necessary feature.

 If Kumar Rajeev Rastogi do not have any extra comments, then I think patch
 is  ready for committer.


Thank you very much

Regards

Pavel


Re: [HACKERS] psql: show only failed queries

2014-06-25 Thread Samrat Revagade
Hi Pavel,

After applying patch, on error condition it displays error message two
times as follows:

ERROR:  column abc does not exist at character 23
STATEMENT:  insert into ax
values(abc);
psql:a.sql:7: ERROR:  column abc does not exist
LINE 2: values(abc);


user may confuse because of repeated error messages. so I think its better
to display only one message, one of the possible ways is as follows:

ERROR:  column abc does not exist at character 23
STATEMENT:  insert into ax
values(abc);


Am I missing something ?



On Wed, Jun 4, 2014 at 9:52 PM, Pavel Stehule pavel.steh...@gmail.com
wrote:




 2014-06-04 18:16 GMT+02:00 Peter Eisentraut pete...@gmx.net:

 On 6/4/14, 11:54 AM, Pavel Stehule wrote:
  updated patch - only one change: query is prefixed by QUERY:  

 In the backend server log, this is called STATEMENT:  .


 good idea

 updated patch

 Pavel


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




-- 
Regards,

Samrat Revgade


Re: [HACKERS] psql: show only failed queries

2014-06-25 Thread Pavel Stehule
2014-06-25 12:32 GMT+02:00 Samrat Revagade revagade.sam...@gmail.com:

 Hi Pavel,

 After applying patch, on error condition it displays error message two
 times as follows:

 ERROR:  column abc does not exist at character 23
 STATEMENT:  insert into ax
 values(abc);
 psql:a.sql:7: ERROR:  column abc does not exist
 LINE 2: values(abc);


 user may confuse because of repeated error messages. so I think its better
 to display only one message, one of the possible ways is as follows:

 ERROR:  column abc does not exist at character 23
 STATEMENT:  insert into ax
 values(abc);


 Am I missing something ?


LINE info is a part of error message and should be eliminated by terse mode


[pavel@localhost ~]$ psql -v ECHO=error  -f test.sql postgres  /dev/null
psql:test.sql:4: ERROR:  syntax error at or near ;
LINE 2: 10 + ;
 ^
psql:test.sql:4: STATEMENT:  select
10 + ;
psql:test.sql:8: ERROR:  syntax error at end of input
LINE 2: 30 +
 ^
psql:test.sql:8: STATEMENT:  select
30 +

but you can switch to terse mode:

[pavel@localhost ~]$ psql -v ECHO=error -v VERBOSITY=terse -f test.sql
postgres  /dev/null
psql:test.sql:4: ERROR:  syntax error at or near ; at character 13
psql:test.sql:4: STATEMENT:  select
10 + ;
psql:test.sql:8: ERROR:  syntax error at end of input at character 13
psql:test.sql:8: STATEMENT:  select
30 +

What is what you would

I am sending updated patch - buggy statement is printed via more logical
psql_error function instead printf

Regards

Pavel





 On Wed, Jun 4, 2014 at 9:52 PM, Pavel Stehule pavel.steh...@gmail.com
 wrote:




 2014-06-04 18:16 GMT+02:00 Peter Eisentraut pete...@gmx.net:

 On 6/4/14, 11:54 AM, Pavel Stehule wrote:
  updated patch - only one change: query is prefixed by QUERY:  

 In the backend server log, this is called STATEMENT:  .


 good idea

 updated patch

 Pavel


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




 --
 Regards,

 Samrat Revgade

commit b269613e0b261a7a5cfea35594299a0dd093682d
Author: Pavel Stehule pavel.steh...@gooddata.com
Date:   Wed Jun 25 20:45:30 2014 +0200

initial

diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index ee6ec3a..cf0e78b 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -2812,7 +2812,8 @@ bar
 literalqueries/literal,
 applicationpsql/application merely prints all queries as
 they are sent to the server. The switch for this is
-option-e/option.
+option-e/option. If set to literalerror/literal then only
+failed queries are displayed.
 /para
 /listitem
   /varlistentry
diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c
index 60169a2..69860d7 100644
--- a/src/bin/psql/common.c
+++ b/src/bin/psql/common.c
@@ -995,6 +995,9 @@ SendQuery(const char *query)
 		results = NULL;			/* PQclear(NULL) does nothing */
 	}
 
+	if (!OK  pset.echo == PSQL_ECHO_ERROR)
+		psql_error(STATEMENT:  %s\n, query);
+
 	/* If we made a temporary savepoint, possibly release/rollback */
 	if (on_error_rollback_savepoint)
 	{
diff --git a/src/bin/psql/settings.h b/src/bin/psql/settings.h
index 0a60e68..e4a18f0 100644
--- a/src/bin/psql/settings.h
+++ b/src/bin/psql/settings.h
@@ -31,6 +31,7 @@ typedef enum
 {
 	PSQL_ECHO_NONE,
 	PSQL_ECHO_QUERIES,
+	PSQL_ECHO_ERROR,
 	PSQL_ECHO_ALL
 } PSQL_ECHO;
 
diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c
index 45653a1..b59bd59 100644
--- a/src/bin/psql/startup.c
+++ b/src/bin/psql/startup.c
@@ -720,6 +720,8 @@ echo_hook(const char *newval)
 		pset.echo = PSQL_ECHO_NONE;
 	else if (strcmp(newval, queries) == 0)
 		pset.echo = PSQL_ECHO_QUERIES;
+	else if (strcmp(newval, error) == 0)
+		pset.echo = PSQL_ECHO_ERROR;
 	else if (strcmp(newval, all) == 0)
 		pset.echo = PSQL_ECHO_ALL;
 	else
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index be5c3c5..8611dd2 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -3591,6 +3591,23 @@ psql_completion(const char *text, int start, int end)
 	{
 		matches = complete_from_variables(text, , );
 	}
+	else if (strcmp(prev2_wd, \\set) == 0)
+	{
+		if (strcmp(prev_wd, ECHO) == 0)
+		{
+			static const char *const my_list[] =
+			{none, error, queries, all, NULL};
+
+			COMPLETE_WITH_LIST_CS(my_list);
+		}
+		else if (strcmp(prev_wd, ECHO_HIDDEN) == 0)
+		{
+			static const char *const my_list[] =
+			{noexec, off, on, NULL};
+
+			COMPLETE_WITH_LIST_CS(my_list);
+		}
+	}
 	else if (strcmp(prev_wd, \\sf) == 0 || strcmp(prev_wd, \\sf+) == 0)
 		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_functions, NULL);
 	else if (strcmp(prev_wd, \\cd) == 0 ||

-- 
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: show only failed queries

2014-06-25 Thread Alvaro Herrera
ECHO_HIDDEN?

-- 
Álvaro Herrerahttp://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


Re: [HACKERS] psql: show only failed queries

2014-06-04 Thread Pavel Stehule
Hello

updated patch - only one change: query is prefixed by QUERY:  

current state:

[pavel@localhost ~]$ src/postgresql/src/bin/psql/psql postgres -q -f
data.sql
psql:data.sql:6: ERROR:  value too long for type character varying(3)

Show only errors mode:

[pavel@localhost ~]$ src/postgresql/src/bin/psql/psql postgres -q -v
ECHO=error -f data.sql
psql:data.sql:6: ERROR:  value too long for type character varying(3)
QUERY:  INSERT INTO bubu VALUES('Ahoj');

Now, when I am thinking about these results, I am thinking, so second
variant is more practical and can be default.

Opinions, notes?

Regards

Pavel




2014-03-04 8:52 GMT+01:00 Pavel Stehule pavel.steh...@gmail.com:




 2014-03-04 6:35 GMT+01:00 Fabrízio de Royes Mello fabriziome...@gmail.com
 :




 On Sat, Mar 1, 2014 at 8:01 AM, Pavel Stehule pavel.steh...@gmail.com
 wrote:
 
  Hello
 
  I was asked, how can be showed only failed queries in psql.
 
  I am thinking, so it is not possible now. But implementation is very
 simple
 
  What do you think about it?
 
  bash-4.1$ psql postgres -v ECHO=error -f data.sql
  INSERT 0 1
  Time: 27.735 ms
  INSERT 0 1
  Time: 8.303 ms
  psql:data.sql:3: ERROR:  value too long for type character varying(2)
  insert into foo values('bbb');
  Time: 0.178 ms
  INSERT 0 1
  Time: 8.285 ms
  psql:data.sql:5: ERROR:  value too long for type character varying(2)
  insert into foo values('ss');
  Time: 0.422 ms
 

 The patch works fine, but I think we must add some prefix to printed
 query. Like that:

 fabrizio=# \set ECHO error
 fabrizio=# insert into foo values ('XXX');

 ERROR:  value too long for type character varying(2)
 DETAIL:  insert into foo values ('XXX');

 or

 fabrizio=# \set ECHO error
 fabrizio=# insert into foo values ('XXX');

 ERROR:  value too long for type character varying(2)
 QUERY:  insert into foo values ('XXX');

 This may help to filter the output with some tool like 'grep'.


 sure, good idea.

 I add link to your notice to commitfest app

 Regards

 Pavel



 Regards,

 --
 Fabrízio de Royes Mello
 Consultoria/Coaching PostgreSQL
  Timbira: http://www.timbira.com.br
  Blog sobre TI: http://fabriziomello.blogspot.com
  Perfil Linkedin: http://br.linkedin.com/in/fabriziomello
  Twitter: http://twitter.com/fabriziomello



commit 47b8944a5d3afb6763096bdd993e256ecae6691d
Author: Pavel Stehule pavel.steh...@gooddata.com
Date:   Wed Jun 4 17:44:54 2014 +0200

initial

diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index ee6ec3a..cf0e78b 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -2812,7 +2812,8 @@ bar
 literalqueries/literal,
 applicationpsql/application merely prints all queries as
 they are sent to the server. The switch for this is
-option-e/option.
+option-e/option. If set to literalerror/literal then only
+failed queries are displayed.
 /para
 /listitem
   /varlistentry
diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c
index 60169a2..5c94c03 100644
--- a/src/bin/psql/common.c
+++ b/src/bin/psql/common.c
@@ -995,6 +995,12 @@ SendQuery(const char *query)
 		results = NULL;			/* PQclear(NULL) does nothing */
 	}
 
+	if (!OK  pset.echo == PSQL_ECHO_ERROR)
+	{
+		printf(QUERY:  %s\n, query);
+		fflush(stdout);
+	}
+
 	/* If we made a temporary savepoint, possibly release/rollback */
 	if (on_error_rollback_savepoint)
 	{
diff --git a/src/bin/psql/settings.h b/src/bin/psql/settings.h
index 0a60e68..e4a18f0 100644
--- a/src/bin/psql/settings.h
+++ b/src/bin/psql/settings.h
@@ -31,6 +31,7 @@ typedef enum
 {
 	PSQL_ECHO_NONE,
 	PSQL_ECHO_QUERIES,
+	PSQL_ECHO_ERROR,
 	PSQL_ECHO_ALL
 } PSQL_ECHO;
 
diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c
index 45653a1..b59bd59 100644
--- a/src/bin/psql/startup.c
+++ b/src/bin/psql/startup.c
@@ -720,6 +720,8 @@ echo_hook(const char *newval)
 		pset.echo = PSQL_ECHO_NONE;
 	else if (strcmp(newval, queries) == 0)
 		pset.echo = PSQL_ECHO_QUERIES;
+	else if (strcmp(newval, error) == 0)
+		pset.echo = PSQL_ECHO_ERROR;
 	else if (strcmp(newval, all) == 0)
 		pset.echo = PSQL_ECHO_ALL;
 	else
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 3bb727f..e5e1558 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -3479,6 +3479,23 @@ psql_completion(const char *text, int start, int end)
 	{
 		matches = complete_from_variables(text, , );
 	}
+	else if (strcmp(prev2_wd, \\set) == 0)
+	{
+		if (strcmp(prev_wd, ECHO) == 0)
+		{
+			static const char *const my_list[] =
+			{none, error, queries, all, NULL};
+
+			COMPLETE_WITH_LIST_CS(my_list);
+		}
+		else if (strcmp(prev_wd, ECHO_HIDDEN) == 0)
+		{
+			static const char *const my_list[] =
+			{noexec, off, on, NULL};
+
+			COMPLETE_WITH_LIST_CS(my_list);
+		}
+	}
 	else if (strcmp(prev_wd, \\sf) == 0 || strcmp(prev_wd, \\sf+) == 0)
 		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_functions, NULL);
 	else 

Re: [HACKERS] psql: show only failed queries

2014-06-04 Thread Peter Eisentraut
On 6/4/14, 11:54 AM, Pavel Stehule wrote:
 updated patch - only one change: query is prefixed by QUERY:  

In the backend server log, this is called STATEMENT:  .



-- 
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: show only failed queries

2014-06-04 Thread Pavel Stehule
2014-06-04 18:16 GMT+02:00 Peter Eisentraut pete...@gmx.net:

 On 6/4/14, 11:54 AM, Pavel Stehule wrote:
  updated patch - only one change: query is prefixed by QUERY:  

 In the backend server log, this is called STATEMENT:  .


good idea

updated patch

Pavel
commit f752566830032438739b7e5ab1f55149c737e6d8
Author: Pavel Stehule pavel.steh...@gooddata.com
Date:   Wed Jun 4 17:44:54 2014 +0200

initial

diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index ee6ec3a..cf0e78b 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -2812,7 +2812,8 @@ bar
 literalqueries/literal,
 applicationpsql/application merely prints all queries as
 they are sent to the server. The switch for this is
-option-e/option.
+option-e/option. If set to literalerror/literal then only
+failed queries are displayed.
 /para
 /listitem
   /varlistentry
diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c
index 60169a2..fed3ee5 100644
--- a/src/bin/psql/common.c
+++ b/src/bin/psql/common.c
@@ -995,6 +995,12 @@ SendQuery(const char *query)
 		results = NULL;			/* PQclear(NULL) does nothing */
 	}
 
+	if (!OK  pset.echo == PSQL_ECHO_ERROR)
+	{
+		printf(STATEMENT:  %s\n, query);
+		fflush(stdout);
+	}
+
 	/* If we made a temporary savepoint, possibly release/rollback */
 	if (on_error_rollback_savepoint)
 	{
diff --git a/src/bin/psql/settings.h b/src/bin/psql/settings.h
index 0a60e68..e4a18f0 100644
--- a/src/bin/psql/settings.h
+++ b/src/bin/psql/settings.h
@@ -31,6 +31,7 @@ typedef enum
 {
 	PSQL_ECHO_NONE,
 	PSQL_ECHO_QUERIES,
+	PSQL_ECHO_ERROR,
 	PSQL_ECHO_ALL
 } PSQL_ECHO;
 
diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c
index 45653a1..b59bd59 100644
--- a/src/bin/psql/startup.c
+++ b/src/bin/psql/startup.c
@@ -720,6 +720,8 @@ echo_hook(const char *newval)
 		pset.echo = PSQL_ECHO_NONE;
 	else if (strcmp(newval, queries) == 0)
 		pset.echo = PSQL_ECHO_QUERIES;
+	else if (strcmp(newval, error) == 0)
+		pset.echo = PSQL_ECHO_ERROR;
 	else if (strcmp(newval, all) == 0)
 		pset.echo = PSQL_ECHO_ALL;
 	else
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 3bb727f..e5e1558 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -3479,6 +3479,23 @@ psql_completion(const char *text, int start, int end)
 	{
 		matches = complete_from_variables(text, , );
 	}
+	else if (strcmp(prev2_wd, \\set) == 0)
+	{
+		if (strcmp(prev_wd, ECHO) == 0)
+		{
+			static const char *const my_list[] =
+			{none, error, queries, all, NULL};
+
+			COMPLETE_WITH_LIST_CS(my_list);
+		}
+		else if (strcmp(prev_wd, ECHO_HIDDEN) == 0)
+		{
+			static const char *const my_list[] =
+			{noexec, off, on, NULL};
+
+			COMPLETE_WITH_LIST_CS(my_list);
+		}
+	}
 	else if (strcmp(prev_wd, \\sf) == 0 || strcmp(prev_wd, \\sf+) == 0)
 		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_functions, NULL);
 	else if (strcmp(prev_wd, \\cd) == 0 ||

-- 
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: show only failed queries

2014-03-03 Thread Fabrízio de Royes Mello
On Sat, Mar 1, 2014 at 8:01 AM, Pavel Stehule pavel.steh...@gmail.com
wrote:

 Hello

 I was asked, how can be showed only failed queries in psql.

 I am thinking, so it is not possible now. But implementation is very
simple

 What do you think about it?

 bash-4.1$ psql postgres -v ECHO=error -f data.sql
 INSERT 0 1
 Time: 27.735 ms
 INSERT 0 1
 Time: 8.303 ms
 psql:data.sql:3: ERROR:  value too long for type character varying(2)
 insert into foo values('bbb');
 Time: 0.178 ms
 INSERT 0 1
 Time: 8.285 ms
 psql:data.sql:5: ERROR:  value too long for type character varying(2)
 insert into foo values('ss');
 Time: 0.422 ms


The patch works fine, but I think we must add some prefix to printed query.
Like that:

fabrizio=# \set ECHO error
fabrizio=# insert into foo values ('XXX');
ERROR:  value too long for type character varying(2)
DETAIL:  insert into foo values ('XXX');

or

fabrizio=# \set ECHO error
fabrizio=# insert into foo values ('XXX');
ERROR:  value too long for type character varying(2)
QUERY:  insert into foo values ('XXX');

This may help to filter the output with some tool like 'grep'.

Regards,

--
Fabrízio de Royes Mello
Consultoria/Coaching PostgreSQL
 Timbira: http://www.timbira.com.br
 Blog sobre TI: http://fabriziomello.blogspot.com
 Perfil Linkedin: http://br.linkedin.com/in/fabriziomello
 Twitter: http://twitter.com/fabriziomello


Re: [HACKERS] psql: show only failed queries

2014-03-03 Thread Pavel Stehule
2014-03-04 6:35 GMT+01:00 Fabrízio de Royes Mello fabriziome...@gmail.com:




 On Sat, Mar 1, 2014 at 8:01 AM, Pavel Stehule pavel.steh...@gmail.com
 wrote:
 
  Hello
 
  I was asked, how can be showed only failed queries in psql.
 
  I am thinking, so it is not possible now. But implementation is very
 simple
 
  What do you think about it?
 
  bash-4.1$ psql postgres -v ECHO=error -f data.sql
  INSERT 0 1
  Time: 27.735 ms
  INSERT 0 1
  Time: 8.303 ms
  psql:data.sql:3: ERROR:  value too long for type character varying(2)
  insert into foo values('bbb');
  Time: 0.178 ms
  INSERT 0 1
  Time: 8.285 ms
  psql:data.sql:5: ERROR:  value too long for type character varying(2)
  insert into foo values('ss');
  Time: 0.422 ms
 

 The patch works fine, but I think we must add some prefix to printed
 query. Like that:

 fabrizio=# \set ECHO error
 fabrizio=# insert into foo values ('XXX');

 ERROR:  value too long for type character varying(2)
 DETAIL:  insert into foo values ('XXX');

 or

 fabrizio=# \set ECHO error
 fabrizio=# insert into foo values ('XXX');

 ERROR:  value too long for type character varying(2)
 QUERY:  insert into foo values ('XXX');

 This may help to filter the output with some tool like 'grep'.


sure, good idea.

I add link to your notice to commitfest app

Regards

Pavel



 Regards,

 --
 Fabrízio de Royes Mello
 Consultoria/Coaching PostgreSQL
  Timbira: http://www.timbira.com.br
  Blog sobre TI: http://fabriziomello.blogspot.com
  Perfil Linkedin: http://br.linkedin.com/in/fabriziomello
  Twitter: http://twitter.com/fabriziomello