pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedpsql removes dashed comments
6+ messages / 4 participants
[nested] [flat]
* psql removes dashed comments
@ 2022-04-07 18:25 Boris Zentner <bzm@2bz.de>
2022-04-07 18:29 ` Re: psql removes dashed comments Adrian Klaver <adrian.klaver@aklaver.com>
2022-04-07 18:41 ` Re: psql removes dashed comments David G. Johnston <david.g.johnston@gmail.com>
2022-04-07 18:48 ` Re: psql removes dashed comments David G. Johnston <david.g.johnston@gmail.com>
0 siblings, 3 replies; 6+ messages in thread
From: Boris Zentner @ 2022-04-07 18:25 UTC (permalink / raw)
To: pgsql-general
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
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: psql removes dashed comments
2022-04-07 18:25 psql removes dashed comments Boris Zentner <bzm@2bz.de>
@ 2022-04-07 18:29 ` Adrian Klaver <adrian.klaver@aklaver.com>
2022-04-07 20:27 ` Re: psql removes dashed comments Tom Lane <tgl@sss.pgh.pa.us>
2 siblings, 1 reply; 6+ messages in thread
From: Adrian Klaver @ 2022-04-07 18:29 UTC (permalink / raw)
To: Boris Zentner <bzm@2bz.de>; pgsql-general
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
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: psql removes dashed comments
2022-04-07 18:25 psql removes dashed comments Boris Zentner <bzm@2bz.de>
2022-04-07 18:29 ` Re: psql removes dashed comments Adrian Klaver <adrian.klaver@aklaver.com>
@ 2022-04-07 20:27 ` Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 6+ messages in thread
From: Tom Lane @ 2022-04-07 20:27 UTC (permalink / raw)
To: Adrian Klaver <adrian.klaver@aklaver.com>; +Cc: Boris Zentner <bzm@2bz.de>; pgsql-general
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%40mai...
regards, tom lane
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: psql removes dashed comments
2022-04-07 18:25 psql removes dashed comments Boris Zentner <bzm@2bz.de>
@ 2022-04-07 18:41 ` David G. Johnston <david.g.johnston@gmail.com>
2022-04-07 19:22 ` Re: psql removes dashed comments Boris Zentner <bzm@2bz.de>
2 siblings, 1 reply; 6+ messages in thread
From: David G. Johnston @ 2022-04-07 18:41 UTC (permalink / raw)
To: Boris Zentner <bzm@2bz.de>; +Cc: pgsql-general
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.
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: psql removes dashed comments
2022-04-07 18:25 psql removes dashed comments Boris Zentner <bzm@2bz.de>
2022-04-07 18:41 ` Re: psql removes dashed comments David G. Johnston <david.g.johnston@gmail.com>
@ 2022-04-07 19:22 ` Boris Zentner <bzm@2bz.de>
0 siblings, 0 replies; 6+ messages in thread
From: Boris Zentner @ 2022-04-07 19:22 UTC (permalink / raw)
To: David G. Johnston <david.g.johnston@gmail.com>; +Cc: pgsql-general
> 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.
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: psql removes dashed comments
2022-04-07 18:25 psql removes dashed comments Boris Zentner <bzm@2bz.de>
@ 2022-04-07 18:48 ` David G. Johnston <david.g.johnston@gmail.com>
2 siblings, 0 replies; 6+ messages in thread
From: David G. Johnston @ 2022-04-07 18:48 UTC (permalink / raw)
To: Boris Zentner <bzm@2bz.de>; +Cc: pgsql-general
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.
^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2022-04-07 20:27 UTC | newest]
Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-04-07 18:25 psql removes dashed comments Boris Zentner <bzm@2bz.de>
2022-04-07 18:29 ` Adrian Klaver <adrian.klaver@aklaver.com>
2022-04-07 20:27 ` Tom Lane <tgl@sss.pgh.pa.us>
2022-04-07 18:41 ` David G. Johnston <david.g.johnston@gmail.com>
2022-04-07 19:22 ` Boris Zentner <bzm@2bz.de>
2022-04-07 18:48 ` David G. Johnston <david.g.johnston@gmail.com>
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