@@ -784,7 +784,7 @@ fn parse_not_precedence() {
784
784
expr: Box :: new( Expr :: Like {
785
785
expr: Box :: new( Expr :: Value ( Value :: SingleQuotedString ( "a" . into( ) ) ) ) ,
786
786
negated: true ,
787
- pattern: Box :: new( Value :: SingleQuotedString ( "b" . into( ) ) ) ,
787
+ pattern: Box :: new( Expr :: Value ( Value :: SingleQuotedString ( "b" . into( ) ) ) ) ,
788
788
escape_char: None
789
789
} ) ,
790
790
} ,
@@ -817,7 +817,7 @@ fn parse_like() {
817
817
Expr :: Like {
818
818
expr: Box :: new( Expr :: Identifier ( Ident :: new( "name" ) ) ) ,
819
819
negated,
820
- pattern: Box :: new( Value :: SingleQuotedString ( "%a" . to_string( ) ) ) ,
820
+ pattern: Box :: new( Expr :: Value ( Value :: SingleQuotedString ( "%a" . to_string( ) ) ) ) ,
821
821
escape_char: None
822
822
} ,
823
823
select. selection. unwrap( )
@@ -833,7 +833,7 @@ fn parse_like() {
833
833
Expr :: Like {
834
834
expr: Box :: new( Expr :: Identifier ( Ident :: new( "name" ) ) ) ,
835
835
negated,
836
- pattern: Box :: new( Value :: SingleQuotedString ( "%a" . to_string( ) ) ) ,
836
+ pattern: Box :: new( Expr :: Value ( Value :: SingleQuotedString ( "%a" . to_string( ) ) ) ) ,
837
837
escape_char: Some ( '\\' )
838
838
} ,
839
839
select. selection. unwrap( )
@@ -850,7 +850,7 @@ fn parse_like() {
850
850
Expr :: IsNull ( Box :: new( Expr :: Like {
851
851
expr: Box :: new( Expr :: Identifier ( Ident :: new( "name" ) ) ) ,
852
852
negated,
853
- pattern: Box :: new( Value :: SingleQuotedString ( "%a" . to_string( ) ) ) ,
853
+ pattern: Box :: new( Expr :: Value ( Value :: SingleQuotedString ( "%a" . to_string( ) ) ) ) ,
854
854
escape_char: None
855
855
} ) ) ,
856
856
select. selection. unwrap( )
@@ -860,6 +860,45 @@ fn parse_like() {
860
860
chk ( true ) ;
861
861
}
862
862
863
+ #[ test]
864
+ fn parse_null_like ( ) {
865
+ let sql = "SELECT \
866
+ column1 LIKE NULL AS col_null, \
867
+ NULL LIKE column1 AS null_col \
868
+ FROM customers";
869
+ let select = verified_only_select ( sql) ;
870
+ assert_eq ! (
871
+ SelectItem :: ExprWithAlias {
872
+ expr: Expr :: Like {
873
+ expr: Box :: new( Expr :: Identifier ( Ident :: new( "column1" ) ) ) ,
874
+ negated: false ,
875
+ pattern: Box :: new( Expr :: Value ( Value :: Null ) ) ,
876
+ escape_char: None
877
+ } ,
878
+ alias: Ident {
879
+ value: "col_null" . to_owned( ) ,
880
+ quote_style: None
881
+ }
882
+ } ,
883
+ select. projection[ 0 ]
884
+ ) ;
885
+ assert_eq ! (
886
+ SelectItem :: ExprWithAlias {
887
+ expr: Expr :: Like {
888
+ expr: Box :: new( Expr :: Value ( Value :: Null ) ) ,
889
+ negated: false ,
890
+ pattern: Box :: new( Expr :: Identifier ( Ident :: new( "column1" ) ) ) ,
891
+ escape_char: None
892
+ } ,
893
+ alias: Ident {
894
+ value: "null_col" . to_owned( ) ,
895
+ quote_style: None
896
+ }
897
+ } ,
898
+ select. projection[ 1 ]
899
+ ) ;
900
+ }
901
+
863
902
#[ test]
864
903
fn parse_ilike ( ) {
865
904
fn chk ( negated : bool ) {
@@ -872,7 +911,7 @@ fn parse_ilike() {
872
911
Expr :: ILike {
873
912
expr: Box :: new( Expr :: Identifier ( Ident :: new( "name" ) ) ) ,
874
913
negated,
875
- pattern: Box :: new( Value :: SingleQuotedString ( "%a" . to_string( ) ) ) ,
914
+ pattern: Box :: new( Expr :: Value ( Value :: SingleQuotedString ( "%a" . to_string( ) ) ) ) ,
876
915
escape_char: None
877
916
} ,
878
917
select. selection. unwrap( )
@@ -888,7 +927,7 @@ fn parse_ilike() {
888
927
Expr :: ILike {
889
928
expr: Box :: new( Expr :: Identifier ( Ident :: new( "name" ) ) ) ,
890
929
negated,
891
- pattern: Box :: new( Value :: SingleQuotedString ( "%a" . to_string( ) ) ) ,
930
+ pattern: Box :: new( Expr :: Value ( Value :: SingleQuotedString ( "%a" . to_string( ) ) ) ) ,
892
931
escape_char: Some ( '^' )
893
932
} ,
894
933
select. selection. unwrap( )
@@ -905,7 +944,7 @@ fn parse_ilike() {
905
944
Expr :: IsNull ( Box :: new( Expr :: ILike {
906
945
expr: Box :: new( Expr :: Identifier ( Ident :: new( "name" ) ) ) ,
907
946
negated,
908
- pattern: Box :: new( Value :: SingleQuotedString ( "%a" . to_string( ) ) ) ,
947
+ pattern: Box :: new( Expr :: Value ( Value :: SingleQuotedString ( "%a" . to_string( ) ) ) ) ,
909
948
escape_char: None
910
949
} ) ) ,
911
950
select. selection. unwrap( )
@@ -927,7 +966,7 @@ fn parse_similar_to() {
927
966
Expr :: SimilarTo {
928
967
expr: Box :: new( Expr :: Identifier ( Ident :: new( "name" ) ) ) ,
929
968
negated,
930
- pattern: Box :: new( Value :: SingleQuotedString ( "%a" . to_string( ) ) ) ,
969
+ pattern: Box :: new( Expr :: Value ( Value :: SingleQuotedString ( "%a" . to_string( ) ) ) ) ,
931
970
escape_char: None
932
971
} ,
933
972
select. selection. unwrap( )
@@ -943,7 +982,7 @@ fn parse_similar_to() {
943
982
Expr :: SimilarTo {
944
983
expr: Box :: new( Expr :: Identifier ( Ident :: new( "name" ) ) ) ,
945
984
negated,
946
- pattern: Box :: new( Value :: SingleQuotedString ( "%a" . to_string( ) ) ) ,
985
+ pattern: Box :: new( Expr :: Value ( Value :: SingleQuotedString ( "%a" . to_string( ) ) ) ) ,
947
986
escape_char: Some ( '\\' )
948
987
} ,
949
988
select. selection. unwrap( )
@@ -959,7 +998,7 @@ fn parse_similar_to() {
959
998
Expr :: IsNull ( Box :: new( Expr :: SimilarTo {
960
999
expr: Box :: new( Expr :: Identifier ( Ident :: new( "name" ) ) ) ,
961
1000
negated,
962
- pattern: Box :: new( Value :: SingleQuotedString ( "%a" . to_string( ) ) ) ,
1001
+ pattern: Box :: new( Expr :: Value ( Value :: SingleQuotedString ( "%a" . to_string( ) ) ) ) ,
963
1002
escape_char: Some ( '\\' )
964
1003
} ) ) ,
965
1004
select. selection. unwrap( )
0 commit comments