@@ -1926,6 +1926,128 @@ fn parse_select_with_numeric_prefix_column_name() {
19261926 }
19271927}
19281928
1929+ #[ test]
1930+ fn parse_qualified_identifiers_with_numeric_prefix ( ) {
1931+ // Case 1: Qualified column name that starts with digits.
1932+ match mysql ( ) . verified_stmt ( "SELECT t.15to29 FROM my_table AS t" ) {
1933+ Statement :: Query ( q) => match * q. body {
1934+ SetExpr :: Select ( s) => match s. projection . last ( ) {
1935+ Some ( SelectItem :: UnnamedExpr ( Expr :: CompoundIdentifier ( parts) ) ) => {
1936+ assert_eq ! ( & [ Ident :: new( "t" ) , Ident :: new( "15to29" ) ] , & parts[ ..] ) ;
1937+ }
1938+ proj => panic ! ( "Unexpected projection: {:?}" , proj) ,
1939+ } ,
1940+ body => panic ! ( "Unexpected statement body: {:?}" , body) ,
1941+ } ,
1942+ stmt => panic ! ( "Unexpected statement: {:?}" , stmt) ,
1943+ }
1944+
1945+ // Case 2: Qualified column name that starts with digits and on its own represents a number.
1946+ match mysql ( ) . verified_stmt ( "SELECT t.15e29 FROM my_table AS t" ) {
1947+ Statement :: Query ( q) => match * q. body {
1948+ SetExpr :: Select ( s) => match s. projection . last ( ) {
1949+ Some ( SelectItem :: UnnamedExpr ( Expr :: CompoundIdentifier ( parts) ) ) => {
1950+ assert_eq ! ( & [ Ident :: new( "t" ) , Ident :: new( "15e29" ) ] , & parts[ ..] ) ;
1951+ }
1952+ proj => panic ! ( "Unexpected projection: {:?}" , proj) ,
1953+ } ,
1954+ body => panic ! ( "Unexpected statement body: {:?}" , body) ,
1955+ } ,
1956+ stmt => panic ! ( "Unexpected statement: {:?}" , stmt) ,
1957+ }
1958+
1959+ // Case 3: Unqualified, the same token is parsed as a number.
1960+ match mysql ( )
1961+ . parse_sql_statements ( "SELECT 15e29 FROM my_table" )
1962+ . unwrap ( )
1963+ . pop ( )
1964+ {
1965+ Some ( Statement :: Query ( q) ) => match * q. body {
1966+ SetExpr :: Select ( s) => match s. projection . last ( ) {
1967+ Some ( SelectItem :: UnnamedExpr ( Expr :: Value ( ValueWithSpan { value, .. } ) ) ) => {
1968+ assert_eq ! ( & number( "15e29" ) , value) ;
1969+ }
1970+ proj => panic ! ( "Unexpected projection: {:?}" , proj) ,
1971+ } ,
1972+ body => panic ! ( "Unexpected statement body: {:?}" , body) ,
1973+ } ,
1974+ stmt => panic ! ( "Unexpected statement: {:?}" , stmt) ,
1975+ }
1976+
1977+ // Case 4: Quoted simple identifier.
1978+ match mysql ( ) . verified_stmt ( "SELECT `15e29` FROM my_table" ) {
1979+ Statement :: Query ( q) => match * q. body {
1980+ SetExpr :: Select ( s) => match s. projection . last ( ) {
1981+ Some ( SelectItem :: UnnamedExpr ( Expr :: Identifier ( name) ) ) => {
1982+ assert_eq ! ( & Ident :: with_quote( '`' , "15e29" ) , name) ;
1983+ }
1984+ proj => panic ! ( "Unexpected projection: {:?}" , proj) ,
1985+ } ,
1986+ body => panic ! ( "Unexpected statement body: {:?}" , body) ,
1987+ } ,
1988+ stmt => panic ! ( "Unexpected statement: {:?}" , stmt) ,
1989+ }
1990+
1991+ // Case 5: Quoted compound identifier.
1992+ match mysql ( ) . verified_stmt ( "SELECT t.`15e29` FROM my_table AS t" ) {
1993+ Statement :: Query ( q) => match * q. body {
1994+ SetExpr :: Select ( s) => match s. projection . last ( ) {
1995+ Some ( SelectItem :: UnnamedExpr ( Expr :: CompoundIdentifier ( parts) ) ) => {
1996+ assert_eq ! (
1997+ & [ Ident :: new( "t" ) , Ident :: with_quote( '`' , "15e29" ) ] ,
1998+ & parts[ ..]
1999+ ) ;
2000+ }
2001+ proj => panic ! ( "Unexpected projection: {:?}" , proj) ,
2002+ } ,
2003+ body => panic ! ( "Unexpected statement body: {:?}" , body) ,
2004+ } ,
2005+ stmt => panic ! ( "Unexpected statement: {:?}" , stmt) ,
2006+ }
2007+
2008+ // Case 6: Multi-level compound identifiers.
2009+ match mysql ( ) . verified_stmt ( "SELECT 1db.1table.1column" ) {
2010+ Statement :: Query ( q) => match * q. body {
2011+ SetExpr :: Select ( s) => match s. projection . last ( ) {
2012+ Some ( SelectItem :: UnnamedExpr ( Expr :: CompoundIdentifier ( parts) ) ) => {
2013+ assert_eq ! (
2014+ & [
2015+ Ident :: new( "1db" ) ,
2016+ Ident :: new( "1table" ) ,
2017+ Ident :: new( "1column" )
2018+ ] ,
2019+ & parts[ ..]
2020+ ) ;
2021+ }
2022+ proj => panic ! ( "Unexpected projection: {:?}" , proj) ,
2023+ } ,
2024+ body => panic ! ( "Unexpected statement body: {:?}" , body) ,
2025+ } ,
2026+ stmt => panic ! ( "Unexpected statement: {:?}" , stmt) ,
2027+ }
2028+
2029+ // Case 7: Multi-level compound quoted identifiers.
2030+ match mysql ( ) . verified_stmt ( "SELECT `1`.`2`.`3`" ) {
2031+ Statement :: Query ( q) => match * q. body {
2032+ SetExpr :: Select ( s) => match s. projection . last ( ) {
2033+ Some ( SelectItem :: UnnamedExpr ( Expr :: CompoundIdentifier ( parts) ) ) => {
2034+ assert_eq ! (
2035+ & [
2036+ Ident :: with_quote( '`' , "1" ) ,
2037+ Ident :: with_quote( '`' , "2" ) ,
2038+ Ident :: with_quote( '`' , "3" )
2039+ ] ,
2040+ & parts[ ..]
2041+ ) ;
2042+ }
2043+ proj => panic ! ( "Unexpected projection: {:?}" , proj) ,
2044+ } ,
2045+ body => panic ! ( "Unexpected statement body: {:?}" , body) ,
2046+ } ,
2047+ stmt => panic ! ( "Unexpected statement: {:?}" , stmt) ,
2048+ }
2049+ }
2050+
19292051// Don't run with bigdecimal as it fails like this on rust beta:
19302052//
19312053// 'parse_select_with_concatenation_of_exp_number_and_numeric_prefix_column'
0 commit comments