@@ -640,6 +640,20 @@ def is_numeric_type_code(type_code, dialect_name: str) -> bool:
640640 type_str = str (type_code ).upper ()
641641 return any (kw in type_str for kw in ['NUMBER' , 'FLOAT' , 'INTEGER' , 'BINARY_FLOAT' , 'BINARY_DOUBLE' ])
642642
643+ if dialect_name == 'clickhouse' :
644+ if isinstance (type_code , str ):
645+ upper_type = type_code .upper ()
646+ # 数值类型关键字
647+ numeric_prefixes = (
648+ 'INT' , # Int8/16/32/64
649+ 'UINT' , # UInt8/16/32/64 ✅ 加上 UINT
650+ 'FLOAT' , # Float32, Float64
651+ 'DECIMAL' , # Decimal, Decimal32/64/128
652+ 'BOOL' , # Bool
653+ 'BIT' , # 极少数场景
654+ )
655+ return any (upper_type .startswith (p ) for p in numeric_prefixes )
656+
643657 # ---------- SQL Server (pyodbc / pymssql) ----------
644658 if dialect_name == 'mssql' :
645659 if isinstance (type_code , int ):
@@ -841,7 +855,7 @@ def build_fields_info_from_cursor(cursor, origin_column, db_type='postgresql'):
841855 for col_info in cursor .description :
842856 col_name = col_info [0 ]
843857
844- if db_type == 'mysql' :
858+ if db_type in ( 'mysql' , 'mariadb' , 'doris' , 'starrocks' ) :
845859 # MySQL/pymysql 类型码
846860 is_numeric = col_info [1 ] in (
847861 1 , # TINYINT
@@ -852,34 +866,32 @@ def build_fields_info_from_cursor(cursor, origin_column, db_type='postgresql'):
852866 8 , # BIGINT
853867 9 , # MEDIUMINT
854868 16 , # BIT
855- 246 , # DECIMAL
869+ 246 , # DECIMAL/NEWDECIMAL
856870 )
857871 elif db_type in ('postgresql' , 'redshift' , 'kingbase' ):
858872 # PostgreSQL/psycopg2 类型 OID
859873 is_numeric = col_info [1 ] in (
874+ 16 , # bool
860875 20 , # int8
861876 21 , # int2
862877 23 , # int4
863878 700 , # float4
864879 701 , # float8
880+ 790 , # money
865881 1700 , # numeric
866- 16 , # boolean
867882 )
868883 elif db_type == 'dm' :
869- # 达梦数据库类型码
870- is_numeric = col_info [1 ] in (
871- 3 , # DECIMAL/NUMERIC
872- 2 , # NUMBER
873- 4 , # INTEGER
874- 5 , # INT
875- 6 , # BIGINT
876- 7 , # TINYINT
877- 8 , # BYTE
878- 9 , # FLOAT
879- 10 , # DOUBLE
880- 11 , # REAL
881- 12 , # BOOLEAN
882- )
884+ # 达梦数据库类型码 <class 'dmPython.DECIMAL'>
885+ # 获取类型类名
886+ type_name = col_info [1 ].__name__ .upper () if hasattr (col_info [1 ], '__name__' ) else str (col_info [1 ]).upper ()
887+
888+ is_numeric = type_name in {
889+ 'INT' , 'INTEGER' ,
890+ 'BIGINT' , 'SMALLINT' , 'TINYINT' ,
891+ 'NUMBER' , 'NUMERIC' , 'DECIMAL' ,
892+ 'FLOAT' , 'DOUBLE' , 'REAL' ,
893+ 'BIT' , 'BOOLEAN' ,
894+ }
883895 elif db_type == 'hive' :
884896 # Hive 类型对象转字符串判断
885897 type_str = str (col_info [1 ]).lower ()
0 commit comments