Re: \set \e and newline

Поиск
Список
Период
Сортировка
От Laurenz Albe
Тема Re: \set \e and newline
Дата
Msg-id 6ac5d86744518febe4bcf0bae5d1bc4cf09363f2.camel@cybertec.at
обсуждение исходный текст
Ответ на \set \e and newline  (Wim Bertels <wim.bertels@ucll.be>)
Ответы Re: \set \e and newline  (Wim Bertels <wim.bertels@ucll.be>)
Список 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




В списке pgsql-general по дате отправления:

Предыдущее
От: Hu Bert
Дата:
Сообщение: After upgrade pg12 -> pg14 import time increased
Следующее
От: Laurenz Albe
Дата:
Сообщение: Re: alter table to multi partitions