psql removes dashed comments
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
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:
/messages/by-id/265623A4-F304-4E68-90D0-343F614DB2B7@americanefficient.com
--
Boris
--
Adrian Klaver
adrian.klaver@aklaver.com
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.
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.
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.
Thanks David! \e filename does indeed help a bit but the file must exists and I have to type and invent the filename before I 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 the runtime of the psql command.
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:
/messages/by-id/265623A4-F304-4E68-90D0-343F614DB2B7@americanefficient.com
This might be more on-point:
/messages/by-id/CAJcOf-cAdMVr7azeYR7nWKsNp7qhORzc84rV6d7m7knG5Hrtsw@mail.gmail.com
regards, tom lane