@@ -862,7 +862,7 @@ fn parse_not_precedence() {
862
862
expr: Box :: new( Expr :: Like {
863
863
expr: Box :: new( Expr :: Value ( Value :: SingleQuotedString ( "a" . into( ) ) ) ) ,
864
864
negated: true ,
865
- pattern: Box :: new( Value :: SingleQuotedString ( "b" . into( ) ) ) ,
865
+ pattern: Box :: new( Expr :: Value ( Value :: SingleQuotedString ( "b" . into( ) ) ) ) ,
866
866
escape_char: None
867
867
} ) ,
868
868
} ,
@@ -895,7 +895,7 @@ fn parse_like() {
895
895
Expr :: Like {
896
896
expr: Box :: new( Expr :: Identifier ( Ident :: new( "name" ) ) ) ,
897
897
negated,
898
- pattern: Box :: new( Value :: SingleQuotedString ( "%a" . to_string( ) ) ) ,
898
+ pattern: Box :: new( Expr :: Value ( Value :: SingleQuotedString ( "%a" . to_string( ) ) ) ) ,
899
899
escape_char: None
900
900
} ,
901
901
select. selection. unwrap( )
@@ -911,7 +911,7 @@ fn parse_like() {
911
911
Expr :: Like {
912
912
expr: Box :: new( Expr :: Identifier ( Ident :: new( "name" ) ) ) ,
913
913
negated,
914
- pattern: Box :: new( Value :: SingleQuotedString ( "%a" . to_string( ) ) ) ,
914
+ pattern: Box :: new( Expr :: Value ( Value :: SingleQuotedString ( "%a" . to_string( ) ) ) ) ,
915
915
escape_char: Some ( '\\' )
916
916
} ,
917
917
select. selection. unwrap( )
@@ -928,7 +928,7 @@ fn parse_like() {
928
928
Expr :: IsNull ( Box :: new( Expr :: Like {
929
929
expr: Box :: new( Expr :: Identifier ( Ident :: new( "name" ) ) ) ,
930
930
negated,
931
- pattern: Box :: new( Value :: SingleQuotedString ( "%a" . to_string( ) ) ) ,
931
+ pattern: Box :: new( Expr :: Value ( Value :: SingleQuotedString ( "%a" . to_string( ) ) ) ) ,
932
932
escape_char: None
933
933
} ) ) ,
934
934
select. selection. unwrap( )
@@ -938,6 +938,45 @@ fn parse_like() {
938
938
chk ( true ) ;
939
939
}
940
940
941
+ #[ test]
942
+ fn parse_null_like ( ) {
943
+ let sql = "SELECT \
944
+ column1 LIKE NULL AS col_null, \
945
+ NULL LIKE column1 AS null_col \
946
+ FROM customers";
947
+ let select = verified_only_select ( sql) ;
948
+ assert_eq ! (
949
+ SelectItem :: ExprWithAlias {
950
+ expr: Expr :: Like {
951
+ expr: Box :: new( Expr :: Identifier ( Ident :: new( "column1" ) ) ) ,
952
+ negated: false ,
953
+ pattern: Box :: new( Expr :: Value ( Value :: Null ) ) ,
954
+ escape_char: None
955
+ } ,
956
+ alias: Ident {
957
+ value: "col_null" . to_owned( ) ,
958
+ quote_style: None
959
+ }
960
+ } ,
961
+ select. projection[ 0 ]
962
+ ) ;
963
+ assert_eq ! (
964
+ SelectItem :: ExprWithAlias {
965
+ expr: Expr :: Like {
966
+ expr: Box :: new( Expr :: Value ( Value :: Null ) ) ,
967
+ negated: false ,
968
+ pattern: Box :: new( Expr :: Identifier ( Ident :: new( "column1" ) ) ) ,
969
+ escape_char: None
970
+ } ,
971
+ alias: Ident {
972
+ value: "null_col" . to_owned( ) ,
973
+ quote_style: None
974
+ }
975
+ } ,
976
+ select. projection[ 1 ]
977
+ ) ;
978
+ }
979
+
941
980
#[ test]
942
981
fn parse_ilike ( ) {
943
982
fn chk ( negated : bool ) {
@@ -950,7 +989,7 @@ fn parse_ilike() {
950
989
Expr :: ILike {
951
990
expr: Box :: new( Expr :: Identifier ( Ident :: new( "name" ) ) ) ,
952
991
negated,
953
- pattern: Box :: new( Value :: SingleQuotedString ( "%a" . to_string( ) ) ) ,
992
+ pattern: Box :: new( Expr :: Value ( Value :: SingleQuotedString ( "%a" . to_string( ) ) ) ) ,
954
993
escape_char: None
955
994
} ,
956
995
select. selection. unwrap( )
@@ -966,7 +1005,7 @@ fn parse_ilike() {
966
1005
Expr :: ILike {
967
1006
expr: Box :: new( Expr :: Identifier ( Ident :: new( "name" ) ) ) ,
968
1007
negated,
969
- pattern: Box :: new( Value :: SingleQuotedString ( "%a" . to_string( ) ) ) ,
1008
+ pattern: Box :: new( Expr :: Value ( Value :: SingleQuotedString ( "%a" . to_string( ) ) ) ) ,
970
1009
escape_char: Some ( '^' )
971
1010
} ,
972
1011
select. selection. unwrap( )
@@ -983,7 +1022,7 @@ fn parse_ilike() {
983
1022
Expr :: IsNull ( Box :: new( Expr :: ILike {
984
1023
expr: Box :: new( Expr :: Identifier ( Ident :: new( "name" ) ) ) ,
985
1024
negated,
986
- pattern: Box :: new( Value :: SingleQuotedString ( "%a" . to_string( ) ) ) ,
1025
+ pattern: Box :: new( Expr :: Value ( Value :: SingleQuotedString ( "%a" . to_string( ) ) ) ) ,
987
1026
escape_char: None
988
1027
} ) ) ,
989
1028
select. selection. unwrap( )
@@ -1005,7 +1044,7 @@ fn parse_similar_to() {
1005
1044
Expr :: SimilarTo {
1006
1045
expr: Box :: new( Expr :: Identifier ( Ident :: new( "name" ) ) ) ,
1007
1046
negated,
1008
- pattern: Box :: new( Value :: SingleQuotedString ( "%a" . to_string( ) ) ) ,
1047
+ pattern: Box :: new( Expr :: Value ( Value :: SingleQuotedString ( "%a" . to_string( ) ) ) ) ,
1009
1048
escape_char: None
1010
1049
} ,
1011
1050
select. selection. unwrap( )
@@ -1021,7 +1060,7 @@ fn parse_similar_to() {
1021
1060
Expr :: SimilarTo {
1022
1061
expr: Box :: new( Expr :: Identifier ( Ident :: new( "name" ) ) ) ,
1023
1062
negated,
1024
- pattern: Box :: new( Value :: SingleQuotedString ( "%a" . to_string( ) ) ) ,
1063
+ pattern: Box :: new( Expr :: Value ( Value :: SingleQuotedString ( "%a" . to_string( ) ) ) ) ,
1025
1064
escape_char: Some ( '\\' )
1026
1065
} ,
1027
1066
select. selection. unwrap( )
@@ -1037,7 +1076,7 @@ fn parse_similar_to() {
1037
1076
Expr :: IsNull ( Box :: new( Expr :: SimilarTo {
1038
1077
expr: Box :: new( Expr :: Identifier ( Ident :: new( "name" ) ) ) ,
1039
1078
negated,
1040
- pattern: Box :: new( Value :: SingleQuotedString ( "%a" . to_string( ) ) ) ,
1079
+ pattern: Box :: new( Expr :: Value ( Value :: SingleQuotedString ( "%a" . to_string( ) ) ) ) ,
1041
1080
escape_char: Some ( '\\' )
1042
1081
} ) ) ,
1043
1082
select. selection. unwrap( )
0 commit comments