Re: psql misbehaves because of a simple typo

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Serguei Mokhov <sa_mokho(at)alcor(dot)concordia(dot)ca>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Peter Eisentraut <peter_e(at)gmx(dot)net>
Subject: Re: psql misbehaves because of a simple typo
Date: 2001-12-28 04:00:36
Message-ID: 200112280400.fBS40aG23633@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> "Serguei Mokhov" <sa_mokho(at)alcor(dot)concordia(dot)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(at)candle(dot)pha(dot)pa(dot)us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2001-12-28 04:11:37 Re: psql misbehaves because of a simple typo
Previous Message Bruce Momjian 2001-12-28 03:30:04 Re: FW: [ppa-dev] Severe bug in debian - phppgadmin opensup