pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Laurenz Albe <laurenz.albe@cybertec.at>
To: wim.bertels@ucll.be
To: pgsql-general@lists.postgresql.org
Subject: Re: \set \e and newline
Date: Fri, 25 Feb 2022 10:33:12 +0100
Message-ID: <6ac5d86744518febe4bcf0bae5d1bc4cf09363f2.camel@cybertec.at> (raw)
In-Reply-To: <75f2f22ccefef9ae79e550a660083b3fe6be038b.camel@ucll.be>
References: <75f2f22ccefef9ae79e550a660083b3fe6be038b.camel@ucll.be>

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






view thread (4+ messages)  latest in thread

Message-ID: <6ac5d86744518febe4bcf0bae5d1bc4cf09363f2.camel@cybertec.at>
Permalink:  ../6ac5d86744518febe4bcf0bae5d1bc4cf09363f2.camel@cybertec.at/
Also on:    postgresql.org/message-id/6ac5d86744518febe4bcf0bae5d1bc4cf09363f2.camel@cybertec.at

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: laurenz.albe@cybertec.at, wim.bertels@ucll.be
  Subject: Re: \set \e and newline
  In-Reply-To: <6ac5d86744518febe4bcf0bae5d1bc4cf09363f2.camel@cybertec.at>
  References: <75f2f22ccefef9ae79e550a660083b3fe6be038b.camel@ucll.be> <6ac5d86744518febe4bcf0bae5d1bc4cf09363f2.camel@cybertec.at>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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