Re: \set \e and newline

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: wim(dot)bertels(at)ucll(dot)be, pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: \set \e and newline
Date: 2022-02-25 09:33:12
Message-ID: 6ac5d86744518febe4bcf0bae5d1bc4cf09363f2.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, 2022-02-24 at 18:16 +0100, Wim Bertels wrote:
> it seems that \set does not interpret an 'enter' interactively the same
> as an 'enter' in a short script made with \e
>
> * case 1:
> postgres=# \set x 1
> postgres=# select :x;
>  ?column?
> ----------
>         1

Ok.

> * case 2:
> postgres=# \e
>
> -- enter the following the editor (the same code as above)
>
> \set x 1
> select :x;
>
> -- save and quit
>
> postgres=#
>
> -- no output

This was interpreted as if you had entered it in a single line:

\set x 1 select :x

So "x" is now "1select1;".

> -- curiosly: again \e
>
> postgres=#\e
>
> -- shows select 1; in the editor in v14

That was the last executed SQL statement.

> -- shows nothing in the editor in v13 (or recursive the content being
> cut off)

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

> 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.

Yours,
Laurenz Albe
--
Cybertec | https://www.cybertec-postgresql.com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Laurenz Albe 2022-02-25 09:36:01 Re: alter table to multi partitions
Previous Message Hu Bert 2022-02-25 08:25:29 After upgrade pg12 -> pg14 import time increased