Thread: psql removes dashed comments

psql removes dashed comments

From
Boris Zentner
Date:
Hi,

I was wondering why psql loose dashed comments and what can be done about this misbehaviour.

I get often some sql, paste it into psql run and edit it via \e. A few iterations until everything works.
But psql removes the comments and creates a lot extra work to restore the comments and changes to the query.

Here is an example:

# start psql, paste something run it, edit \e, rerun and so on. At the end all dashed comments are removed.


psql -Xe postgres
psql (14.1)
Type "help" for help.

postgres=# select 1, -- one
 2, /* two */
 3 -- three
;
select 1,
 2, /* two */
 3
;
 ?column? | ?column? | ?column?
----------+----------+----------
        1 |        2 |        3
(1 row)

postgres=# \e
select 1,
 2, /* two */
 3
;
 ?column? | ?column? | ?column?
----------+----------+----------
        1 |        2 |        3
(1 row)

--
Boris





Re: psql removes dashed comments

From
Adrian Klaver
Date:
On 4/7/22 11:25, Boris Zentner wrote:
> Hi,
> 
> I was wondering why psql loose dashed comments and what can be done about this misbehaviour.

See this recent thread:

https://www.postgresql.org/message-id/265623A4-F304-4E68-90D0-343F614DB2B7%40americanefficient.com



> --
> Boris
> 
> 
> 
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com



Re: psql removes dashed comments

From
"David G. Johnston"
Date:
On Thursday, April 7, 2022, Boris Zentner <bzm@2bz.de> wrote:

I was wondering why psql loose dashed comments and what can be done about this misbehaviour.

postgres=# \e


Because \e treats the query buffer as a single line of code and dashed comments cannot be used, just like meta-commands cannot be used.

Including a filename should establish the behavior you desire.

David J. 
 

Re: psql removes dashed comments

From
"David G. Johnston"
Date:
On Thursday, April 7, 2022, Boris Zentner <bzm@2bz.de> wrote:
Hi,

I was wondering why psql loose dashed comments and what can be done about this misbehaviour.

# start psql, paste something run it, edit \e, rerun and so on. At the end all dashed comments are removed.


psql -Xe postgres
psql (14.1)
Type "help" for help.

postgres=# select 1, -- one
 2, /* two */
 3 -- three
;
select 1,
 2, /* two */
 3
;
 ?column? | ?column? | ?column?
----------+----------+----------
        1 |        2 |        3
(1 row)

postgres=# \e
select 1,
 2, /* two */
 3
;
 ?column? | ?column? | ?column?
----------+----------+----------
        1 |        2 |        3
(1 row)



My last comment seems a bit off, but all you’ve done here is demonstrate the documented behavior when the query buffer contains multiple commands when \e is executed.

In either case this is working as documented and you really should be using a permanent file for this kind of thing.

David J.

 

Re: psql removes dashed comments

From
Boris Zentner
Date:
> I was wondering why psql loose dashed comments and what can be done about this misbehaviour.
>
> postgres=# \e
>
>
> Because \e treats the query buffer as a single line of code and dashed comments cannot be used, just like
meta-commandscannot be used. 
>
> Including a filename should establish the behavior you desire.
>
Thanks David! \e filename does indeed help a bit but the file must exists and I have to type and invent the filename
beforeI start. 
My workaround was \! vim xyz.sql but it is not satisfying.

Without thinking to depth about this, maybe a new meta command could help?
Something like \eee to fill an initially empty temporary file from the query buffer on the first call and reuse it over
theruntime of the psql command. 


Re: psql removes dashed comments

From
Tom Lane
Date:
Adrian Klaver <adrian.klaver@aklaver.com> writes:
> On 4/7/22 11:25, Boris Zentner wrote:
>> I was wondering why psql loose dashed comments and what can be done about this misbehaviour.

> See this recent thread:
> https://www.postgresql.org/message-id/265623A4-F304-4E68-90D0-343F614DB2B7%40americanefficient.com

This might be more on-point:

https://www.postgresql.org/message-id/flat/CAJcOf-cAdMVr7azeYR7nWKsNp7qhORzc84rV6d7m7knG5Hrtsw%40mail.gmail.com

            regards, tom lane