Re: psql misbehaves because of a simple typo - Mailing list pgsql-hackers

From Bruce Momjian
Subject Re: psql misbehaves because of a simple typo
Date
Msg-id 200112280400.fBS40aG23633@candle.pha.pa.us
Whole thread Raw
In response to Re: psql misbehaves because of a simple typo  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: psql misbehaves because of a simple typo  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
> "Serguei Mokhov" <sa_mokho@alcor.concordia.ca> writes:
> > Is it me (who hasn't read some FAQ or a doc/man page) or
> > it's a bug in the psql interactive terminal?
> 
> Both.  There's a bug there, but it's not the one you think.
> psql seems to forget that it's got unmatched parentheses in the
> buffer after executing a \? command.  Watch the prompt:
> 
> regression=# (select
> regression(# \?
>  ... yadda yadda ...
> regression-# 2;
> ERROR:  parser: parse error at or near ";"
> regression=# (select
> regression(# \?
>  ... yadda yadda ...
> regression-# 2);
>  ?column?
> ----------
>         2
> (1 row)
> 
> In the first example, it should not have thought that it had
> a complete command after "2;".

The actual code that resets the paren level is:
/* backslash command */else if (was_bslash){    const char *end_of_cmd = NULL;
    paren_level = 0;    line[i - prevlen] = '\0'; /* overwrites backslash */

I believe this code is good.  If someone issues a backslash command,
they probably want to get out of they paren nesting, or may not even
know they are in paren nesting, as Serguei did not in the example shown.

While it doesn't seem logical, it does help prevent people from getting
stuck in psql.  The fact that backslash commands inside parens clear the
counter is a minor anoyance but resonable behavior.

--  Bruce Momjian                        |  http://candle.pha.pa.us pgman@candle.pha.pa.us               |  (610)
853-3000+  If your life is a hard drive,     |  830 Blythe Avenue +  Christ can be your backup.        |  Drexel Hill,
Pennsylvania19026
 


pgsql-hackers by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: FW: [ppa-dev] Severe bug in debian - phppgadmin opensup
Next
From: Tom Lane
Date:
Subject: Re: psql misbehaves because of a simple typo