Re: \set \e and newline

From: Wim Bertels <wim(dot)bertels(at)ucll(dot)be>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: \set \e and newline
Date: 2022-02-28 11:34:24
Message-ID: d317e3d0e3d9efe3173e4473fbee927f955db4a4.camel@ucll.be
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Laurenz Albe schreef op vr 25-02-2022 om 10:33 [+0100]:
> On Thu, 2022-02-24 at 18:16 +0100, Wim Bertels wrote:
> This was interpreted as if you had entered it in a single line:
>
> \set x 1 select :x
>
> So "x" is now "1select1;".

yes

>
> I don't quite understand what you mean, but the behavior of \e
> changed
> (got more sane) in v14.

yes,
(this is just a summary of different cases)

>
> > variation of case 2:
> > postgres=# \e
> >
> > -- enter the following the editor (the same code as above)
> >
> > \set x 1
> > select :x;
> >
> > -- save and quit
> >
> > postgres=# select :x;
> >  select1select1
> > ----------------
> >               1
>
> Now "x" is "1select1select1;;", so you are running
>
>  select 1select1select1;;;
>
> Here "select1select1" is interpreted as alias, so you get that column
> heading.
>
> You can use "\echo :x" to see the value of a variable.
>

Thanks for the feedback Laurenz

I guess the main remark is, it not so intuitive that \e behaves
differently then \i

From https://www.postgresql.org/docs/current/app-psql.html
"
\e..
Type semicolon or \g to send it, or \r to cancel it by clearing the
query buffer.

Treating the buffer as a single line primarily affects meta-commands:
whatever is in the buffer after a meta-command will be taken as
argument(s) to the meta-command, even if it spans multiple lines. (Thus
you cannot make meta-command-using scripts this way. Use \i for that.)
"

### case 1: (\e)
\set x 1
select :x ;

### case 2: (\e)
\set x 1
select :x \g

resulting in the same value for x (\echo :x), but different
intermediate output with case 1 and case 2,

"
\g..
If the current query buffer is empty, the most recently sent query is
re-executed instead. Except for that behavior, \g without any arguments
is essentially equivalent to a semicolon.
"

mvg,
Wim

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Laurenz Albe 2022-02-28 17:37:46 Re: \set \e and newline
Previous Message Lucas 2022-02-28 03:31:31 Re: PG 14 Create Rule ERROR - RETURNING list has too few entries