sql server - pandas + pyodbc ODBC SQL type -150 is not yet supported -
i know there many topics on think specific. current code audit purpose:
import pandas pd import pyodbc query = """ --top 50 high total cpu queries select top 50 'high cpu queries' type, serverproperty('machinename') 'server name', isnull(serverproperty('instancename'),serverproperty('machinename')) 'instance name', coalesce(db_name(qt.dbid), db_name(cast(pa.value int)), 'resource') dbname, qs.execution_count [execution count], qs.total_worker_time/1000 [total cpu time], (qs.total_worker_time/1000)/qs.execution_count [avg cpu time], qs.total_elapsed_time/1000 [total duration], (qs.total_elapsed_time/1000)/qs.execution_count [avg duration], qs.total_physical_reads [total physical reads], qs.total_physical_reads/qs.execution_count [avg physical reads], qs.total_logical_reads [total logical reads], qs.total_logical_reads/qs.execution_count [avg logical reads], substring(qt.text,qs.statement_start_offset/2, (case when qs.statement_end_offset = -1 len(convert(nvarchar(max), qt.text)) * 2 else qs.statement_end_offset end -qs.statement_start_offset)/2) query_text sys.dm_exec_query_stats qs cross apply sys.dm_exec_sql_text(qs.sql_handle) qt outer apply sys.dm_exec_query_plan (qs.plan_handle) qp outer apply sys.dm_exec_plan_attributes(qs.plan_handle) pa attribute = 'dbid' order [total cpu time] desc """ cnxn = pyodbc.connect('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx') cnxn.execute(query).fetchall() cnxn.close()
i following error:
cnxn.execute(sql_status_20).fetchall() traceback (most recent call last): file "", line 1, in pyodbc.programmingerror: ('odbc sql type -150 not yet supported. column-index=1 type=-150', 'hy106')
anyone can me handle ? have same problem many sql server audit scripts using dates , can't change driver have kind of sql versions in production env.
if can't change driver, you'll need change query return data types supports.
sql type -150 sql_variant
, returned serverproperty
. workaround explicitly cast
column supported type nvarchar
:
cast(serverproperty('machinename') nvarchar(100)) 'server name', cast(isnull(serverproperty('instancename'),serverproperty('machinename')) nvarchar(100)) 'instance name',
Comments
Post a Comment