@@ -332,7 +332,6 @@ fn parse_select_distinct_two_fields() {
332
332
let sql = "SELECT DISTINCT name, id FROM customer" ;
333
333
let select = verified_only_select ( sql) ;
334
334
assert ! ( select. distinct) ;
335
- one_statement_parses_to ( "SELECT DISTINCT (name, id) FROM customer" , sql) ;
336
335
assert_eq ! (
337
336
& SelectItem :: UnnamedExpr ( Expr :: Identifier ( Ident :: new( "name" ) ) ) ,
338
337
& select. projection[ 0 ]
@@ -343,6 +342,19 @@ fn parse_select_distinct_two_fields() {
343
342
) ;
344
343
}
345
344
345
+ #[ test]
346
+ fn parse_select_distinct_tuple ( ) {
347
+ let sql = "SELECT DISTINCT (name, id) FROM customer" ;
348
+ let select = verified_only_select ( sql) ;
349
+ assert_eq ! (
350
+ & vec![ SelectItem :: UnnamedExpr ( Expr :: Tuple ( vec![
351
+ Expr :: Identifier ( Ident :: new( "name" ) ) ,
352
+ Expr :: Identifier ( Ident :: new( "id" ) ) ,
353
+ ] ) ) ] ,
354
+ & select. projection
355
+ ) ;
356
+ }
357
+
346
358
#[ test]
347
359
fn parse_select_distinct_missing_paren ( ) {
348
360
let result = parse_sql_statements ( "SELECT DISTINCT (name, id FROM customer" ) ;
@@ -1033,6 +1045,44 @@ fn parse_between_with_expr() {
1033
1045
)
1034
1046
}
1035
1047
1048
+ #[ test]
1049
+ fn parse_tuples ( ) {
1050
+ let sql = "SELECT (1, 2), (1), ('foo', 3, baz)" ;
1051
+ let select = verified_only_select ( sql) ;
1052
+ assert_eq ! (
1053
+ vec![
1054
+ SelectItem :: UnnamedExpr ( Expr :: Tuple ( vec![
1055
+ Expr :: Value ( number( "1" ) ) ,
1056
+ Expr :: Value ( number( "2" ) )
1057
+ ] ) ) ,
1058
+ SelectItem :: UnnamedExpr ( Expr :: Nested ( Box :: new( Expr :: Value ( number( "1" ) ) ) ) ) ,
1059
+ SelectItem :: UnnamedExpr ( Expr :: Tuple ( vec![
1060
+ Expr :: Value ( Value :: SingleQuotedString ( "foo" . into( ) ) ) ,
1061
+ Expr :: Value ( number( "3" ) ) ,
1062
+ Expr :: Identifier ( Ident :: new( "baz" ) )
1063
+ ] ) )
1064
+ ] ,
1065
+ select. projection
1066
+ ) ;
1067
+ }
1068
+
1069
+ #[ test]
1070
+ fn parse_tuple_invalid ( ) {
1071
+ let sql = "select (1" ;
1072
+ let res = parse_sql_statements ( sql) ;
1073
+ assert_eq ! (
1074
+ ParserError :: ParserError ( "Expected ), found: EOF" . to_string( ) ) ,
1075
+ res. unwrap_err( )
1076
+ ) ;
1077
+
1078
+ let sql = "select (), 2" ;
1079
+ let res = parse_sql_statements ( sql) ;
1080
+ assert_eq ! (
1081
+ ParserError :: ParserError ( "Expected an expression:, found: )" . to_string( ) ) ,
1082
+ res. unwrap_err( )
1083
+ ) ;
1084
+ }
1085
+
1036
1086
#[ test]
1037
1087
fn parse_select_order_by ( ) {
1038
1088
fn chk ( sql : & str ) {
@@ -1121,6 +1171,12 @@ fn parse_select_group_by() {
1121
1171
] ,
1122
1172
select. group_by
1123
1173
) ;
1174
+
1175
+ // Tuples can also be in the set
1176
+ one_statement_parses_to (
1177
+ "SELECT id, fname, lname FROM customer GROUP BY (lname, fname)" ,
1178
+ "SELECT id, fname, lname FROM customer GROUP BY (lname, fname)" ,
1179
+ ) ;
1124
1180
}
1125
1181
1126
1182
#[ test]
0 commit comments