From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Rob Sargent <robjsargent(at)gmail(dot)com> |
Cc: | pgsql-general(at)lists(dot)postgresql(dot)org |
Subject: | Re: Leading comments and client applications |
Date: | 2022-03-25 19:30:25 |
Message-ID: | 3457456.1648236625@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Rob Sargent <robjsargent(at)gmail(dot)com> writes:
>> As far as the comparison behavior goes, psql's parser strips
>> comments that start with double dashes, for $obscure_reasons.
> That story aught to be worth a $beer or two
Hmm. The original reasoning is lost in the mists of time;
I dug in our git history and traced the behavior as far back
as a45195a19 of 1999-11-04, but I'll bet a nickel that Peter
doesn't remember exactly why he did that.
But I can show you why I gave up on removing the behavior:
it's an important part of psql's strategy of discarding
leading whitespace before a query. Our regression test
scripts are full of cases like
-- comments here
SELECT intentionally-wrong-query;
and what they're expecting to get from that is output like
ERROR: column "intentionally" does not exist
LINE 1: SELECT intentionally-wrong-query;
^
When I changed psql's parser to not remove comments, that output
suddenly changed to say "LINE 3:", because now the query string
sent to the server included the "-- comments here" line as well
as the blank line after it. While we could have changed all the
expected output, or changed how the server counts lines within
a query, we concluded that this would confuse too many people and
break too many applications; so we left it alone.
(As of v15, psql will send -- comments that begin *after* the
first non-whitespace token of a query [1]. But leading comments
and whitespace will still get stripped.)
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Rob Sargent | 2022-03-25 19:35:13 | Re: Leading comments and client applications |
Previous Message | Philip Semanchuk | 2022-03-25 18:05:50 | Re: Leading comments and client applications |