PostgreSQL Comments – SQL Comments Disappear with psql and \e

commentspostgresqlpsql

Is there anyway at all, ever to change the behavior of comments in psql. Take the query below. Execute it.

CREATE TABLE foo
AS
  SELECT x AS id,
    -- x AS id2,
    x AS id3
  FROM generate_series(1,50) AS x;

Run that in psql. Then run \e. Now at least, for me what I see in my editor is the line absent. This is driving me crazy. Is there a way around this.. The comment is just absent from the buffer that gets passed to the editor. Often, it's commented and not deleted because I want to uncomment it at a later point.

Comment gone

Best Answer

Workaround with C-style comments

For whatever reason.. this seems to work when you use C-style comments instead of standard SQL comments,

CREATE TABLE foo
AS
  SELECT x AS id,
    /* x AS id2, */
    x AS id3
  FROM generate_series(1,50) AS x;

Now you can do \e and edit it.