Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8388468

Browse files
committed
psql: include intra-query "--" comments in what's sent to the server.
psql's lexer has historically deleted dash-dash (single-line) commentsfrom what's collected and sent to the server. This is inconsistentwith what it does for slash-star comments, and people have complainedbefore that they wish such comments would be captured in the server log.Undoing the decision completely seems like too big a behavioral change,however. In particular, comments on lines preceding the start of aquery are generally not thought of as being part of that query.What we can do to improve the situation is to capture comments thatare clearly *within* a query, that is after the first non-whitespace,non-comment token but before the query's ending semicolon or backslashcommand. This is a nearly trivial code change, and it affects only afew regression test results.(It is tempting to try to apply the same rule to slash-star comments.But it's hard to see how to do that without getting strange historybehavior for comments that cross lines, especially if the user thenstarts a new query on the same line as the star-slash. In view ofthe lack of complaints, let's leave that case alone.)Discussion:https://postgr.es/m/CAJcOf-cAdMVr7azeYR7nWKsNp7qhORzc84rV6d7m7knG5Hrtsw@mail.gmail.com
1 parent89d1c15 commit8388468

File tree

5 files changed

+11
-12
lines changed

5 files changed

+11
-12
lines changed

‎contrib/pg_stat_statements/expected/pg_stat_statements.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ SELECT query, calls, rows FROM pg_stat_statements ORDER BY query COLLATE "C";
101101
------------------------------------------------------------------------------+-------+------
102102
PREPARE pgss_test (int) AS SELECT $1, $2 LIMIT $3 | 1 | 1
103103
SELECT $1 +| 4 | 4
104-
+| |
104+
-- multiline +| |
105105
AS "text" | |
106106
SELECT $1 + $2 | 2 | 2
107107
SELECT $1 + $2 + $3 AS "add" | 3 | 3

‎src/fe_utils/psqlscan.l

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -378,12 +378,11 @@ other.
378378
/*
379379
* Note that the whitespace rule includes both true
380380
* whitespace and single-line ("--" style) comments.
381-
* We suppress whitespace at the start of the query
382-
* buffer. We also suppress all single-line comments,
383-
* which is pretty dubious but is the historical
384-
* behavior.
381+
* We suppress whitespace until we have collected some
382+
* non-whitespace data. (This interacts with some
383+
* decisions in MainLoop(); see there for details.)
385384
*/
386-
if (!(output_buf->len==0 || yytext[0] =='-'))
385+
if (output_buf->len>0)
387386
ECHO;
388387
}
389388

‎src/test/regress/expected/aggregates.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1905,14 +1905,14 @@ from generate_series(1,5) x,
19051905
(values (0::float8),(0.1),(0.25),(0.4),(0.5),(0.6),(0.75),(0.9),(1)) v(p)
19061906
group by p order by p;
19071907
ERROR: sum is not an ordered-set aggregate, so it cannot have WITHIN GROUP
1908-
LINE 1: select p, sum() within group (order by x::float8)
1908+
LINE 1: select p, sum() within group (order by x::float8)-- error
19091909
^
19101910
select p, percentile_cont(p,p) -- error
19111911
from generate_series(1,5) x,
19121912
(values (0::float8),(0.1),(0.25),(0.4),(0.5),(0.6),(0.75),(0.9),(1)) v(p)
19131913
group by p order by p;
19141914
ERROR: WITHIN GROUP is required for ordered-set aggregate percentile_cont
1915-
LINE 1: select p, percentile_cont(p,p)
1915+
LINE 1: select p, percentile_cont(p,p)-- error
19161916
^
19171917
select percentile_cont(0.5) within group (order by b) from aggtest;
19181918
percentile_cont

‎src/test/regress/expected/generated.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -928,15 +928,15 @@ CREATE TRIGGER gtest2a BEFORE INSERT OR UPDATE ON gtest26
928928
WHEN (NEW.b < 0) -- error
929929
EXECUTE PROCEDURE gtest_trigger_func();
930930
ERROR: BEFORE trigger's WHEN condition cannot reference NEW generated columns
931-
LINE 3: WHEN (NEW.b < 0)
931+
LINE 3: WHEN (NEW.b < 0)-- error
932932
^
933933
DETAIL: Column "b" is a generated column.
934934
CREATE TRIGGER gtest2b BEFORE INSERT OR UPDATE ON gtest26
935935
FOR EACH ROW
936936
WHEN (NEW.* IS NOT NULL) -- error
937937
EXECUTE PROCEDURE gtest_trigger_func();
938938
ERROR: BEFORE trigger's WHEN condition cannot reference NEW generated columns
939-
LINE 3: WHEN (NEW.* IS NOT NULL)
939+
LINE 3: WHEN (NEW.* IS NOT NULL)-- error
940940
^
941941
DETAIL: A whole-row reference is used and the table contains generated columns.
942942
CREATE TRIGGER gtest2 BEFORE INSERT ON gtest26

‎src/test/regress/expected/with.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2100,7 +2100,7 @@ WITH outermost(x) AS (
21002100
)
21012101
SELECT * FROM outermost ORDER BY 1;
21022102
ERROR: relation "outermost" does not exist
2103-
LINE 4: SELECT * FROM outermost
2103+
LINE 4: SELECT * FROM outermost-- fail
21042104
^
21052105
DETAIL: There is a WITH item named "outermost", but it cannot be referenced from this part of the query.
21062106
HINT: Use WITH RECURSIVE, or re-order the WITH items to remove forward references.
@@ -2124,7 +2124,7 @@ WITH RECURSIVE outermost(x) AS (
21242124
)
21252125
SELECT * FROM outermost ORDER BY 1;
21262126
ERROR: recursive reference to query "outermost" must not appear within a subquery
2127-
LINE 2: WITH innermost as (SELECT 2 FROM outermost)
2127+
LINE 2: WITH innermost as (SELECT 2 FROM outermost)-- fail
21282128
^
21292129
--
21302130
-- This test will fail with the old implementation of PARAM_EXEC parameter

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp