Re: Leading comments and client applications

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Leading comments and client applications
Дата
Msg-id 3457456.1648236625@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Leading comments and client applications  (Rob Sargent <robjsargent@gmail.com>)
Ответы Re: Leading comments and client applications  (Rob Sargent <robjsargent@gmail.com>)
Список pgsql-general
Rob Sargent <robjsargent@gmail.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

[1] https://git.postgresql.org/gitweb/?p=postgresql.git&a=commitdiff&h=83884682f4df96184549b91869a1cf79dafb4f94



В списке pgsql-general по дате отправления:

Предыдущее
От: Philip Semanchuk
Дата:
Сообщение: Re: Leading comments and client applications
Следующее
От: Rob Sargent
Дата:
Сообщение: Re: Leading comments and client applications