-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
119034: plpgsql: misc fixes for parsing and formatting identifiers and constants r=DrewKimball a=DrewKimball #### plpgsql: correctly format variable names in declarations This commit fixes formatting for variable and cursor declarations to use `FmtCtx.FormatNode` instead of `FormatString`. This ensures that variable names are correctly redacted when applicable, and that complex identifiers round-trip through the parser. Informs #106368 Release note (bug fix): Fixed a bug that prevented the use of PL/pgSQL routines with complex variable names that require double quotes. This bug has existed since v23.2. #### plpgsql/parser: propagate errors during string scanning This commit fixes handling for string constants in the PL/pgSQL parser. Now, the PL/pgSQL scanner handles string scanning itself instead of delegating to the SQL scanner. This ensures that the correct token ID is used when an error occurs (e.g. unterminated string). This commit also adds a check for the ERROR token during PL/pgSQL lexing, so that a scanning error is noticed and propagated back to the user. Informs #106368 Release note (bug fix): Fixed a bug that could cause creation of a syntactically invalid PL/pgSQL routine to return the wrong error. This bug has existed since v23.2. #### plpgsql/parser: fix parsing for escaped strings This commit adds support for scanning an escaped string constant in a PL/pgSQL routine. This is necessary because escaped strings have imbalanced quotes (like `e'foobar''`), which previously caused the scanner to return an "unterminated string" error. Informs #106368 Release note (bug fix): Fixed a bug that could result in a syntax error if a PL/pgSQL routine was created with an escaped string constant in the routine body. This bug has existed since v23.2. 119507: sql: normalize results for float aggregate functions r=DrewKimball a=DrewKimball This commit normalizes the results of the float aggregates that should return return a non-negative result, to account for floating-point errors. This should decreases the rate of randomized test failures due to this problem. Fixes #118733 Release note: None Co-authored-by: Drew Kimball <drewk@cockroachlabs.com>
- Loading branch information
Showing
13 changed files
with
454 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
parse | ||
DECLARE | ||
x STRING := e'1GW\''; | ||
BEGIN | ||
INSERT INTO tab SELECT e'1GW\''; | ||
END | ||
---- | ||
DECLARE | ||
x STRING := e'1GW\''; | ||
BEGIN | ||
INSERT INTO tab SELECT e'1GW\''; | ||
END; | ||
-- normalized! | ||
DECLARE | ||
x STRING := (e'1GW\''); | ||
BEGIN | ||
INSERT INTO tab SELECT (e'1GW\''); | ||
END; | ||
-- fully parenthesized | ||
DECLARE | ||
x STRING := '_'; | ||
BEGIN | ||
INSERT INTO tab SELECT '_'; | ||
END; | ||
-- literals removed | ||
DECLARE | ||
_ STRING := e'1GW\''; | ||
BEGIN | ||
INSERT INTO _ SELECT e'1GW\''; | ||
END; | ||
-- identifiers removed | ||
|
||
parse | ||
DECLARE | ||
x STRING := b'1GW\''; | ||
BEGIN | ||
INSERT INTO tab SELECT b'1GW\''; | ||
END | ||
---- | ||
DECLARE | ||
x STRING := b'1GW\''; | ||
BEGIN | ||
INSERT INTO tab SELECT b'1GW\''; | ||
END; | ||
-- normalized! | ||
DECLARE | ||
x STRING := (b'1GW\''); | ||
BEGIN | ||
INSERT INTO tab SELECT (b'1GW\''); | ||
END; | ||
-- fully parenthesized | ||
DECLARE | ||
x STRING := '_'; | ||
BEGIN | ||
INSERT INTO tab SELECT '_'; | ||
END; | ||
-- literals removed | ||
DECLARE | ||
_ STRING := b'1GW\''; | ||
BEGIN | ||
INSERT INTO _ SELECT b'1GW\''; | ||
END; | ||
-- identifiers removed | ||
|
||
parse | ||
DECLARE | ||
x STRING := x'deadbeef'; | ||
BEGIN | ||
INSERT INTO tab SELECT x'deadbeef'; | ||
END | ||
---- | ||
DECLARE | ||
x STRING := b'\xde\xad\xbe\xef'; | ||
BEGIN | ||
INSERT INTO tab SELECT b'\xde\xad\xbe\xef'; | ||
END; | ||
-- normalized! | ||
DECLARE | ||
x STRING := (b'\xde\xad\xbe\xef'); | ||
BEGIN | ||
INSERT INTO tab SELECT (b'\xde\xad\xbe\xef'); | ||
END; | ||
-- fully parenthesized | ||
DECLARE | ||
x STRING := '_'; | ||
BEGIN | ||
INSERT INTO tab SELECT '_'; | ||
END; | ||
-- literals removed | ||
DECLARE | ||
_ STRING := b'\xde\xad\xbe\xef'; | ||
BEGIN | ||
INSERT INTO _ SELECT b'\xde\xad\xbe\xef'; | ||
END; | ||
-- identifiers removed | ||
|
||
parse | ||
DECLARE | ||
x STRING := B'010101'; | ||
BEGIN | ||
INSERT INTO tab SELECT B'010101'; | ||
END | ||
---- | ||
DECLARE | ||
x STRING := B'010101'; | ||
BEGIN | ||
INSERT INTO tab SELECT B'010101'; | ||
END; | ||
-- normalized! | ||
DECLARE | ||
x STRING := (B'010101'); | ||
BEGIN | ||
INSERT INTO tab SELECT (B'010101'); | ||
END; | ||
-- fully parenthesized | ||
DECLARE | ||
x STRING := _; | ||
BEGIN | ||
INSERT INTO tab SELECT _; | ||
END; | ||
-- literals removed | ||
DECLARE | ||
_ STRING := B'010101'; | ||
BEGIN | ||
INSERT INTO _ SELECT B'010101'; | ||
END; | ||
-- identifiers removed | ||
|
||
error | ||
DECLARE | ||
x STRING := 'foo; | ||
BEGIN | ||
RETURN x; | ||
END | ||
---- | ||
at or near ":": syntax error: unterminated string | ||
DETAIL: source SQL: | ||
DECLARE | ||
x STRING := 'foo; | ||
^ | ||
|
||
error | ||
DECLARE | ||
x STRING := $foo$ foo; | ||
BEGIN | ||
RETURN x; | ||
END | ||
---- | ||
at or near ":": syntax error: unterminated string | ||
DETAIL: source SQL: | ||
DECLARE | ||
x STRING := $foo$ foo; | ||
^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.