@@ -379,6 +379,7 @@ fn parse_update_set_from() {
379379 body: Box :: new( SetExpr :: Select ( Box :: new( Select {
380380 distinct: None ,
381381 top: None ,
382+ top_before_distinct: false ,
382383 projection: vec![
383384 SelectItem :: UnnamedExpr ( Expr :: Identifier ( Ident :: new( "name" ) ) ) ,
384385 SelectItem :: UnnamedExpr ( Expr :: Identifier ( Ident :: new( "id" ) ) ) ,
@@ -4649,6 +4650,7 @@ fn test_parse_named_window() {
46494650 let expected = Select {
46504651 distinct : None ,
46514652 top : None ,
4653+ top_before_distinct : false ,
46524654 projection : vec ! [
46534655 SelectItem :: ExprWithAlias {
46544656 expr: Expr :: Function ( Function {
@@ -5289,6 +5291,7 @@ fn parse_interval_and_or_xor() {
52895291 body: Box :: new( SetExpr :: Select ( Box :: new( Select {
52905292 distinct: None ,
52915293 top: None ,
5294+ top_before_distinct: false ,
52925295 projection: vec![ UnnamedExpr ( Expr :: Identifier ( Ident {
52935296 value: "col" . to_string( ) ,
52945297 quote_style: None ,
@@ -7367,6 +7370,7 @@ fn lateral_function() {
73677370 let expected = Select {
73687371 distinct : None ,
73697372 top : None ,
7373+ top_before_distinct : false ,
73707374 projection : vec ! [ SelectItem :: Wildcard ( WildcardAdditionalOptions {
73717375 opt_ilike: None ,
73727376 opt_exclude: None ,
@@ -8215,6 +8219,7 @@ fn parse_merge() {
82158219 body: Box :: new( SetExpr :: Select ( Box :: new( Select {
82168220 distinct: None ,
82178221 top: None ,
8222+ top_before_distinct: false ,
82188223 projection: vec![ SelectItem :: Wildcard (
82198224 WildcardAdditionalOptions :: default ( )
82208225 ) ] ,
@@ -9803,6 +9808,7 @@ fn parse_unload() {
98039808 body: Box :: new( SetExpr :: Select ( Box :: new( Select {
98049809 distinct: None ,
98059810 top: None ,
9811+ top_before_distinct: false ,
98069812 projection: vec![ UnnamedExpr ( Expr :: Identifier ( Ident :: new( "cola" ) ) ) , ] ,
98079813 into: None ,
98089814 from: vec![ TableWithJoins {
@@ -9978,6 +9984,7 @@ fn parse_connect_by() {
99789984 let expect_query = Select {
99799985 distinct : None ,
99809986 top : None ,
9987+ top_before_distinct : false ,
99819988 projection : vec ! [
99829989 SelectItem :: UnnamedExpr ( Expr :: Identifier ( Ident :: new( "employee_id" ) ) ) ,
99839990 SelectItem :: UnnamedExpr ( Expr :: Identifier ( Ident :: new( "manager_id" ) ) ) ,
@@ -10064,6 +10071,7 @@ fn parse_connect_by() {
1006410071 Select {
1006510072 distinct: None ,
1006610073 top: None ,
10074+ top_before_distinct: false ,
1006710075 projection: vec![
1006810076 SelectItem :: UnnamedExpr ( Expr :: Identifier ( Ident :: new( "employee_id" ) ) ) ,
1006910077 SelectItem :: UnnamedExpr ( Expr :: Identifier ( Ident :: new( "manager_id" ) ) ) ,
@@ -11475,3 +11483,13 @@ fn parse_notify_channel() {
1147511483 ) ;
1147611484 }
1147711485}
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