pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
\set \e and newline
4+ messages / 2 participants
[nested] [flat]

* \set \e and newline
@ 2022-02-24 17:16 Wim Bertels <wim.bertels@ucll.be>
  2022-02-25 09:33 ` Re: \set \e and newline Laurenz Albe <laurenz.albe@cybertec.at>
  0 siblings, 1 reply; 4+ messages in thread

From: Wim Bertels @ 2022-02-24 17:16 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

Hello,

a quick question about
https://www.postgresql.org/docs/current/app-psql.html
and the \set option

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


###
* 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
-- curiosly: again \e

postgres=#\e

-- shows select 1; in the editor in v14
-- shows nothing in the editor in v13 (or recursive the content being
cut off)
###


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

###


Doing the same thing with \i instead of \e does behave like i would
expect, ie the same as case 1.

This is referred to as meta-commands in de manual which are to be
affected when using \e, but \g instead of ; seems to work (while it
should be the same?)


###
variation of case 2 using \g instead of ; :
postgres=# \e

-- enter the following the editor (the same code as above)

\set x 1
select :x \g

-- save and quit

 ?column? 
----------
        1
(1 row)

postgres=# 
###


-- 
mvg,
Wim







^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: \set \e and newline
  2022-02-24 17:16 \set \e and newline Wim Bertels <wim.bertels@ucll.be>
@ 2022-02-25 09:33 ` Laurenz Albe <laurenz.albe@cybertec.at>
  2022-02-28 11:34   ` Re: \set \e and newline Wim Bertels <wim.bertels@ucll.be>
  0 siblings, 1 reply; 4+ messages in thread

From: Laurenz Albe @ 2022-02-25 09:33 UTC (permalink / raw)
  To: wim.bertels@ucll.be; pgsql-general@lists.postgresql.org

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






^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: \set \e and newline
  2022-02-24 17:16 \set \e and newline Wim Bertels <wim.bertels@ucll.be>
  2022-02-25 09:33 ` Re: \set \e and newline Laurenz Albe <laurenz.albe@cybertec.at>
@ 2022-02-28 11:34   ` Wim Bertels <wim.bertels@ucll.be>
  2022-02-28 17:37     ` Re: \set \e and newline Laurenz Albe <laurenz.albe@cybertec.at>
  0 siblings, 1 reply; 4+ messages in thread

From: Wim Bertels @ 2022-02-28 11:34 UTC (permalink / raw)
  To: Laurenz Albe <laurenz.albe@cybertec.at>; pgsql-general@lists.postgresql.org

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



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: \set \e and newline
  2022-02-24 17:16 \set \e and newline Wim Bertels <wim.bertels@ucll.be>
  2022-02-25 09:33 ` Re: \set \e and newline Laurenz Albe <laurenz.albe@cybertec.at>
  2022-02-28 11:34   ` Re: \set \e and newline Wim Bertels <wim.bertels@ucll.be>
@ 2022-02-28 17:37     ` Laurenz Albe <laurenz.albe@cybertec.at>
  0 siblings, 0 replies; 4+ messages in thread

From: Laurenz Albe @ 2022-02-28 17:37 UTC (permalink / raw)
  To: wim.bertels@ucll.be; pgsql-general@lists.postgresql.org

On Mon, 2022-02-28 at 12:34 +0100, Wim Bertels wrote:
> I guess the main remark is, it not so intuitive that \e behaves
> differently then \i

Ok, but if the differences are well documented, it should be ok.

You could submit a patch that changes the behavior, but people
might be unhappy if established, well documented behavior changes...

Yours,
Laurenz Albe






^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2022-02-28 17:37 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-02-24 17:16 \set \e and newline Wim Bertels <wim.bertels@ucll.be>
2022-02-25 09:33 ` Laurenz Albe <laurenz.albe@cybertec.at>
2022-02-28 11:34   ` Wim Bertels <wim.bertels@ucll.be>
2022-02-28 17:37     ` Laurenz Albe <laurenz.albe@cybertec.at>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox