@@ -379,6 +379,7 @@ fn parse_update_set_from() {
379
379
body: Box :: new( SetExpr :: Select ( Box :: new( Select {
380
380
distinct: None ,
381
381
top: None ,
382
+ top_before_distinct: false ,
382
383
projection: vec![
383
384
SelectItem :: UnnamedExpr ( Expr :: Identifier ( Ident :: new( "name" ) ) ) ,
384
385
SelectItem :: UnnamedExpr ( Expr :: Identifier ( Ident :: new( "id" ) ) ) ,
@@ -4649,6 +4650,7 @@ fn test_parse_named_window() {
4649
4650
let expected = Select {
4650
4651
distinct : None ,
4651
4652
top : None ,
4653
+ top_before_distinct : false ,
4652
4654
projection : vec ! [
4653
4655
SelectItem :: ExprWithAlias {
4654
4656
expr: Expr :: Function ( Function {
@@ -5289,6 +5291,7 @@ fn parse_interval_and_or_xor() {
5289
5291
body: Box :: new( SetExpr :: Select ( Box :: new( Select {
5290
5292
distinct: None ,
5291
5293
top: None ,
5294
+ top_before_distinct: false ,
5292
5295
projection: vec![ UnnamedExpr ( Expr :: Identifier ( Ident {
5293
5296
value: "col" . to_string( ) ,
5294
5297
quote_style: None ,
@@ -7367,6 +7370,7 @@ fn lateral_function() {
7367
7370
let expected = Select {
7368
7371
distinct : None ,
7369
7372
top : None ,
7373
+ top_before_distinct : false ,
7370
7374
projection : vec ! [ SelectItem :: Wildcard ( WildcardAdditionalOptions {
7371
7375
opt_ilike: None ,
7372
7376
opt_exclude: None ,
@@ -8215,6 +8219,7 @@ fn parse_merge() {
8215
8219
body: Box :: new( SetExpr :: Select ( Box :: new( Select {
8216
8220
distinct: None ,
8217
8221
top: None ,
8222
+ top_before_distinct: false ,
8218
8223
projection: vec![ SelectItem :: Wildcard (
8219
8224
WildcardAdditionalOptions :: default ( )
8220
8225
) ] ,
@@ -9803,6 +9808,7 @@ fn parse_unload() {
9803
9808
body: Box :: new( SetExpr :: Select ( Box :: new( Select {
9804
9809
distinct: None ,
9805
9810
top: None ,
9811
+ top_before_distinct: false ,
9806
9812
projection: vec![ UnnamedExpr ( Expr :: Identifier ( Ident :: new( "cola" ) ) ) , ] ,
9807
9813
into: None ,
9808
9814
from: vec![ TableWithJoins {
@@ -9978,6 +9984,7 @@ fn parse_connect_by() {
9978
9984
let expect_query = Select {
9979
9985
distinct : None ,
9980
9986
top : None ,
9987
+ top_before_distinct : false ,
9981
9988
projection : vec ! [
9982
9989
SelectItem :: UnnamedExpr ( Expr :: Identifier ( Ident :: new( "employee_id" ) ) ) ,
9983
9990
SelectItem :: UnnamedExpr ( Expr :: Identifier ( Ident :: new( "manager_id" ) ) ) ,
@@ -10064,6 +10071,7 @@ fn parse_connect_by() {
10064
10071
Select {
10065
10072
distinct: None ,
10066
10073
top: None ,
10074
+ top_before_distinct: false ,
10067
10075
projection: vec![
10068
10076
SelectItem :: UnnamedExpr ( Expr :: Identifier ( Ident :: new( "employee_id" ) ) ) ,
10069
10077
SelectItem :: UnnamedExpr ( Expr :: Identifier ( Ident :: new( "manager_id" ) ) ) ,
@@ -11475,3 +11483,13 @@ fn parse_notify_channel() {
11475
11483
) ;
11476
11484
}
11477
11485
}
11486
+
11487
+ #[ test]
11488
+ fn test_select_top ( ) {
11489
+ let dialects = all_dialects_where ( |d| d. supports_top_before_distinct ( ) ) ;
11490
+ dialects. one_statement_parses_to ( "SELECT ALL * FROM tbl" , "SELECT * FROM tbl" ) ;
11491
+ dialects. verified_stmt ( "SELECT TOP 3 * FROM tbl" ) ;
11492
+ dialects. one_statement_parses_to ( "SELECT TOP 3 ALL * FROM tbl" , "SELECT TOP 3 * FROM tbl" ) ;
11493
+ dialects. verified_stmt ( "SELECT TOP 3 DISTINCT * FROM tbl" ) ;
11494
+ dialects. verified_stmt ( "SELECT TOP 3 DISTINCT a, b, c FROM tbl" ) ;
11495
+ }
0 commit comments