From f88d294dd01d72ac17af7167a66607b154f4d8a3 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Wed, 15 May 2024 06:01:49 +0200 Subject: [PATCH] Allow trailing comma in the `Values` format --- src/Processors/Formats/Impl/ValuesBlockInputFormat.cpp | 7 +++++++ ...03153_trailing_comma_in_values_list_in_insert.reference | 3 +++ .../03153_trailing_comma_in_values_list_in_insert.sql | 5 +++++ 3 files changed, 15 insertions(+) create mode 100644 tests/queries/0_stateless/03153_trailing_comma_in_values_list_in_insert.reference create mode 100644 tests/queries/0_stateless/03153_trailing_comma_in_values_list_in_insert.sql diff --git a/src/Processors/Formats/Impl/ValuesBlockInputFormat.cpp b/src/Processors/Formats/Impl/ValuesBlockInputFormat.cpp index 353de76eea8..1493779ec2d 100644 --- a/src/Processors/Formats/Impl/ValuesBlockInputFormat.cpp +++ b/src/Processors/Formats/Impl/ValuesBlockInputFormat.cpp @@ -572,9 +572,16 @@ bool ValuesBlockInputFormat::checkDelimiterAfterValue(size_t column_idx) skipWhitespaceIfAny(*buf); if (likely(column_idx + 1 != num_columns)) + { return checkChar(',', *buf); + } else + { + /// Optional trailing comma. + if (checkChar(',', *buf)) + skipWhitespaceIfAny(*buf); return checkChar(')', *buf); + } } bool ValuesBlockInputFormat::shouldDeduceNewTemplate(size_t column_idx) diff --git a/tests/queries/0_stateless/03153_trailing_comma_in_values_list_in_insert.reference b/tests/queries/0_stateless/03153_trailing_comma_in_values_list_in_insert.reference new file mode 100644 index 00000000000..e115855485d --- /dev/null +++ b/tests/queries/0_stateless/03153_trailing_comma_in_values_list_in_insert.reference @@ -0,0 +1,3 @@ +1 2 3 +4 5 6 +7 8 9 diff --git a/tests/queries/0_stateless/03153_trailing_comma_in_values_list_in_insert.sql b/tests/queries/0_stateless/03153_trailing_comma_in_values_list_in_insert.sql new file mode 100644 index 00000000000..65301c977c2 --- /dev/null +++ b/tests/queries/0_stateless/03153_trailing_comma_in_values_list_in_insert.sql @@ -0,0 +1,5 @@ +CREATE TEMPORARY TABLE test (a UInt8, b UInt8, c UInt8); +INSERT INTO test (a, b, c) VALUES (1, 2, 3, ); +INSERT INTO test (a, b, c) VALUES (4, 5, 6,); +INSERT INTO test (a, b, c) VALUES (7, 8, 9); +SELECT * FROM test ORDER BY a;