HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

SQL Comments disappear with psql and `\e`

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
sqlwithpsqldisappearandcomments

Problem

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.

Solution

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.

Code Snippets

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

Context

StackExchange Database Administrators Q#166630, answer score: 6

Revisions (0)

No revisions yet.