Index: src/bin/psql/mainloop.c
===================================================================
RCS file: /cvsroot/pgsql/src/bin/psql/mainloop.c,v
retrieving revision 1.75
diff -c -c -r1.75 mainloop.c
*** src/bin/psql/mainloop.c	4 Jun 2006 04:35:55 -0000	1.75
--- src/bin/psql/mainloop.c	5 Jun 2006 03:50:11 -0000
***************
*** 41,47 ****
  	char	   *line;			/* current line of input */
  	int			added_nl_pos;
  	bool		success;
! 	bool		first_query_scan;
  	
  	volatile int successResult = EXIT_SUCCESS;
  	volatile backslashResult slashCmdStatus = PSQL_CMD_UNKNOWN;
--- 41,47 ----
  	char	   *line;			/* current line of input */
  	int			added_nl_pos;
  	bool		success;
! 	bool		line_saved_in_history;
  	
  	volatile int successResult = EXIT_SUCCESS;
  	volatile backslashResult slashCmdStatus = PSQL_CMD_UNKNOWN;
***************
*** 80,85 ****
--- 80,87 ----
  	/* main loop to get queries and execute them */
  	while (successResult == EXIT_SUCCESS)
  	{
+ 		line_saved_in_history = false;
+ 
  		/*
  		 * Welcome code for Control-C
  		 */
***************
*** 154,159 ****
--- 156,163 ----
  				 */
  				pg_write_history(history_buf->data);
  				pg_clear_history(history_buf);
+ 				pg_write_history(line);
+ 				line_saved_in_history = true;
  			}
  		}
  		/* otherwise, get another line */
***************
*** 226,232 ****
  		 */
  		psql_scan_setup(scan_state, line, strlen(line));
  		success = true;
- 		first_query_scan = true;
  		
  		while (success || !die_on_error)
  		{
--- 230,235 ----
***************
*** 303,319 ****
  			 *	down here so we can check for \g and other 'execute'
  			 *	backslash commands, which should be appended.
  			 */
! 			if (first_query_scan && pset.cur_cmd_interactive)
  			{
  				/* Sending a command (PSQL_CMD_SEND) zeros the length */
  				if (scan_result == PSCAN_BACKSLASH && history_buf->len != 0)
  					pg_write_history(line);
  				else
  					pg_append_history(line, history_buf);
  			}
  
- 			first_query_scan = false;
- 
  			/* fall out of loop on \q or if lexer reached EOL */
  			if (slashCmdStatus == PSQL_CMD_TERMINATE ||
  				scan_result == PSCAN_INCOMPLETE ||
--- 306,321 ----
  			 *	down here so we can check for \g and other 'execute'
  			 *	backslash commands, which should be appended.
  			 */
! 			if (!line_saved_in_history && pset.cur_cmd_interactive)
  			{
  				/* Sending a command (PSQL_CMD_SEND) zeros the length */
  				if (scan_result == PSCAN_BACKSLASH && history_buf->len != 0)
  					pg_write_history(line);
  				else
  					pg_append_history(line, history_buf);
+ 				line_saved_in_history = true;
  			}
  
  			/* fall out of loop on \q or if lexer reached EOL */
  			if (slashCmdStatus == PSQL_CMD_TERMINATE ||
  				scan_result == PSCAN_INCOMPLETE ||
