Re: psql slash# command

From: "Sibte Abbas" <sibtay(at)gmail(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-patches(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: psql slash# command
Date: 2008-04-03 23:54:23
Message-ID: bd6a35510804031654m5336b47bh3ab876d123defd26@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches

On Sun, Mar 30, 2008 at 3:09 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

>
> I looked this over and realized that it has little to do with the
> functionality that was so painfully hashed out in the original
> discussion thread here:
>
> http://archives.postgresql.org/pgsql-hackers/2006-12/msg00207.php
>
> As I understood it, the consensus was:
>
> 1. Invent a switch (probably a variable instead of a dedicated \-command)
> that determines whether \s includes command numbers in its output.
>
> 2. Add "\# n" to re-execute command number n.
>
> You've twisted this around into
>
> >> \#: displays the command history. Like \s but prefixes the lines with
> line
> >> numbers
> >>
> >> \# <line_no>: executes the command(if any) executed at the line
> specified by
> >> line_no
>

This patch implements the specification described here:

http://archives.postgresql.org/pgsql-hackers/2006-12/msg00255.php

>
>
> This is a serious regression in functionality from what was agreed to,
> because there is no possibility of shoehorning the equivalent of "\s file"
> into it --- you've already decided that any argument is a line number.

It made sense to assume anything following a \# to be a number, since "#"
here denotes a number. However in order to prevent from bad input, there is
a check in the get_hist_entry() function.

> > The attached patch adds the following new functionality:
> > \#e <lineno>: Will open the command at the given lineno in an editor.
> > \#e with no lineno will behave exactly like \e.
>
> None of that was anywhere in the original discussion; and what pray
> tell is the use of the second variant?

The above mentioned link contains definitions for both of these. Also the
second variant here is just for completeness sake.

> I wonder whether it wouldn't be safer and more convenient if we defined
> '\# n' as pulling command n into the edit buffer, rather than
> immediately executing it. Actual execution is only a <return> away,
> but this definition would allow you to edit the command a bit more
> before you execute it --- including \e to use an editor. It also
> closes the loop in terms of providing some confidence that you typed
> the number you should have typed.
>

This makes more sense and also appears to be much safer. I will start
modifying the patch as per this approach now.

regards,
-- Sibte Abbas

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Gregory Stark 2008-04-04 00:00:11 Re: About numeric division again
Previous Message Ron Mayer 2008-04-03 23:42:47 Re: [GENERAL] SHA1 on postgres 8.3

Browse pgsql-patches by date

  From Date Subject
Next Message Tom Lane 2008-04-04 00:29:18 Re: Expose checkpoint start/finish times into SQL.
Previous Message Tom Lane 2008-04-03 23:30:20 Re: psql \G command -- send query and output using extended format