Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d75e4-0002xF-FD for pgsql-bugs@arkaria.postgresql.org; Sat, 06 May 2017 19:45:36 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1d75e2-0006ps-Ve for pgsql-bugs@arkaria.postgresql.org; Sat, 06 May 2017 19:45:35 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1d75e2-0006pK-GI for pgsql-bugs@postgresql.org; Sat, 06 May 2017 19:45:34 +0000 Received: from mail.aegee.org ([144.76.142.78]) by magus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d75dd-0004n2-M2 for pgsql-bugs@postgresql.org; Sat, 06 May 2017 19:45:33 +0000 Authentication-Results: aegeeserv.aegee.org; auth=pass (PLAIN) smtp.auth=didopalauzov DKIM-Filter: OpenDKIM Filter v2.10.3 mail.aegee.org v46JkQNx023274 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aegee.org; s=k4096; t=1494099987; i=dkim+MSA-tls@aegee.org; r=y; bh=Hby1FnT+es/MHmO425RCOguf25gZjshHhbkPS/N04IU=; h=Subject:To:References:From:Date:In-Reply-To; b=OACSGGQWNfEqo/GyRZ77W1f7A5O8M8AzHgQaONyH91QuDFzE138pXjm2hpu1CGk6t VsL3URLqMnujsMZP7Zq9FEK7V/dQz4vQmtymYo05UNdir1F8b2YKRsxp8+YOBwCFCO Hl33Ir9RSrAffZAelyrFoOOTKd9AGBPiv6V90KlWcNtIO5Bq/bbtj+edfF+u6v3ZbN 3MyzVG2Zois/NMs0HO4GkfdOJEMMh5GSryC7L/UsEaN8Ff6/iA3XJz4O5Vl4mSti+t v4NIZrudkWcgKBVH2iaIujLlsofAK9ilA5693ltxEMTmDzE+2Ovpti+oQf9V2Rqqv2 djBFnQwBrmIyUQda16DawQtS/TbM6D2dJa/Nk/H8mm5Cr7G7N3716q9Yw5xUkRuHSY cRVAqaz+znCVVgsexa/5LRyAfHpOOYb3wqlBcp3WTGvN5I+qz5lWFO5jA90vjgs5Q7 Hi0Tkazcny46SZ6qLh9Iz5dKv7XycjV7A3dM/J93q1RiNdetTmako8RQXofUAc9MZO JVOWOtZmWClcvY8mIot1clbmNifzcG9uItleza0eaoSuzBpfIJzX0n48UItkqH+uwM M+PHHOInxCZ0i25ZQvXn7pUCPMePy9uFwCB6l2FDIMhgZU30OwjWtqtLdVvVeN7Cqu ph6dxjDEd1lWMwsODL0xSpBM= Authentication-Results: mail.aegee.org; dkim=none Received: from [192.168.178.39] (x5f74ef1e.dyn.telefonica.de [95.116.239.30]) (authenticated bits=0) by mail.aegee.org (8.15.2/8.15.2) with ESMTPSA id v46JkQNx023274 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO) for ; Sat, 6 May 2017 19:46:27 GMT Subject: Re: psql history and "-- lines" To: pgsql-bugs@postgresql.org References: <48b3a5ac-d219-6568-6751-260b1387bc37@aegee.org> <19006.1494033923@sss.pgh.pa.us> From: =?UTF-8?B?0JTQuNC70Y/QvSDQn9Cw0LvQsNGD0LfQvtCy?= Message-ID: Date: Sat, 6 May 2017 21:45:08 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <19006.1494033923@sss.pgh.pa.us> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: clamav-milter 0.99.2 at mail.aegee.org X-Virus-Status: Clean X-Pg-Spam-Score: -2.0 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org Hello, I expect that psql and the shell, e.g. bash, behave in the same way in regards to history logs and until-the-current-line comments. /* such comments * are out of scope */ SELECT 'here'; In bash, when I start typing a line, that I want to execute later, I put # in the beginning of the line, and later I go with C-p to that line. Another possibility to mark the line as comment is with the insert-comment (M-#) readline command/binding, which prepends # the line and generates . In psql M-# puts also # at the beginning of the line, but this shall be altered to a "--" prefix instead. (To be precise, it inserts the character associated with comment-begin). Fix: diff --git a/src/bin/psql/input.c b/src/bin/psql/input.c --- a/src/bin/psql/input.c +++ b/src/bin/psql/input.c @@ -356,6 +356,7 @@ initializeInput(int flags) /* these two things must be done in this order: */ initialize_readline(); rl_initialize(); + rl_variable_bind("comment-begin", "--"); useHistory = true; using_history(); Both bash and psql append to .bash_history / .psql_history, only when invoked in interactive mode: echo 'echo "X"'| bash # does not alter .bash_history echo 'echo "X"'| bash -i # appends to .bash_history echo "SELECT '1';" | psql # does not amend to .psql_history psql << Z # does not append to .psql_history > SELECT '1'; > Z psql -f whatever.sql # does not add to .psql_history psql -c "SELECT '1';" # likewise psql # does add '\i whatever.sql' to .psql_history, not the file content db=> \i whatever.sql db=> \q Concerning the example from system_views.sql, where eight comment lines precede "CREATE OR REPLACE FUNCTION pg_start_backup": I do not want to type eight lines of comments in an interactive shell. In the case, where the comments are yanked from another source, I still want to have each comment line as separate history entry, as this is consistent with how comments are logged in bash and I am used to. Probably /* such things */ can be used to enforce logging with the subsequent command in contrast to "--". Regards Дилян On 05/06/2017 03:25 AM, Tom Lane wrote: > "David G. Johnston" writes: >> On Fri, May 5, 2017 at 1:52 PM, Дилян Палаузов >> wrote: >>> Could you plexe alter psql, so that it logs two lines in the history for >>> the mentioned case? > >> It probably should only behave as you suggest in --single-line mode... > > I'm not exactly convinced that the proposed change would be an > improvement. Consider code along the lines of (actual example > from system_views.sql): > > -- > -- Redeclare built-in functions that need default values attached to their > -- arguments. It's impractical to set those up directly in pg_proc.h because > -- of the complexity and platform-dependency of the expression tree > -- representation. (Note that internal functions still have to have entries > -- in pg_proc.h; we are merely causing their proargnames and proargdefaults > -- to get filled in.) > -- > > CREATE OR REPLACE FUNCTION > pg_start_backup(label text, fast boolean DEFAULT false, exclusive boolean DEFAULT true) > RETURNS pg_lsn STRICT VOLATILE LANGUAGE internal AS 'pg_start_backup' > PARALLEL RESTRICTED; > > Would you really want each of those -- lines to be their own history > entry? > > Another angle to think about is /* ... */ comments, which you really > can't break into separate lines without creating a syntactically-invalid > mess. That type of comment also creates the possibility of input like > > /* foo > * bar */ select ... > > There isn't any very nice way to separate this comment from the SQL query > for history purposes. > > In my own usage, I think having leading comments being treated as > part of the SQL command is a good thing --- they're sort of a unit, > in most cases. > > regards, tom lane > -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs