@@ -295,8 +295,6 @@ class Parser(parser.Parser):
295295
296296 FUNCTIONS = {
297297 ** parser .Parser .FUNCTIONS ,
298- "CHAR_LENGTH" : exp .Length .from_arg_list ,
299- "CHARACTER_LENGTH" : exp .Length .from_arg_list ,
300298 "CONVERT_TZ" : lambda args : exp .ConvertTimezone (
301299 source_tz = seq_get (args , 1 ), target_tz = seq_get (args , 2 ), timestamp = seq_get (args , 0 )
302300 ),
@@ -311,6 +309,7 @@ class Parser(parser.Parser):
311309 "FORMAT" : exp .NumberToStr .from_arg_list ,
312310 "FROM_UNIXTIME" : build_formatted_time (exp .UnixToTime , "mysql" ),
313311 "ISNULL" : isnull_to_is_null ,
312+ "LENGTH" : lambda args : exp .Length (this = seq_get (args , 0 ), binary = True ),
314313 "LOCATE" : locate_to_strposition ,
315314 "MAKETIME" : exp .TimeFromParts .from_arg_list ,
316315 "MONTH" : lambda args : exp .Month (this = exp .TsOrDsToDate (this = seq_get (args , 0 ))),
@@ -731,7 +730,6 @@ class Generator(generator.Generator):
731730 e : f"""GROUP_CONCAT({ self .sql (e , "this" )} SEPARATOR { self .sql (e , "separator" ) or "','" } )""" ,
732731 exp .ILike : no_ilike_sql ,
733732 exp .JSONExtractScalar : arrow_json_extract_sql ,
734- exp .Length : rename_func ("CHAR_LENGTH" ),
735733 exp .LogicalOr : rename_func ("MAX" ),
736734 exp .LogicalAnd : rename_func ("MIN" ),
737735 exp .Max : max_or_greatest ,
@@ -1265,3 +1263,7 @@ def attimezone_sql(self, expression: exp.AtTimeZone) -> str:
12651263
12661264 def isascii_sql (self , expression : exp .IsAscii ) -> str :
12671265 return f"REGEXP_LIKE({ self .sql (expression .this )} , '^[[:ascii:]]*$')"
1266+
1267+ def length_sql (self , expression : exp .Length ) -> str :
1268+ length_func = "LENGTH" if expression .args .get ("binary" ) else "CHAR_LENGTH"
1269+ return self .func (length_func , expression .this )
0 commit comments