현재 시퀀스에서 첫 번째 질의에 다음과 같은 오류가 발생, (MS sql server
에서) SQL 쿼리의 순서를 읽고 dataframe으로 검토 pandas
을 pyodbc
를 사용하려고하고 :실행 순서
sql_in = """
SET NOCOUNT ON;
select <stuff> from <table1> into #<temptable1>
----SPLIT
SET NOCOUNT ON;
select <stuff> from <table2> into #<temptable2>
----SPLIT
SET NOCOUNT ON;
select <stuff> from <table3> into #<temptable3>
----SPLIT
SET NOCOUNT ON;
select <stuff> from <table4> <joined with temptables1-3> into #<temptable4>
""".split('----SPLIT')
for count, q in enumerate(sql_in):
print count
frame_in = pd.read_sql(q, cnxn)
최종 임시 테이블에 있기 때문에에만 관심이 방법을 완료 조언은 0을 기록 때문에 (split
를 사용 : 같은
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-95-5eec1638614b> in <module>()
285 for count, q in enumerate(sql_in):
286 print count
--> 287 frame_in = pd.read_sql(q, cnxn)
288 print frame_in.head(n=10)
289
/home/mapr/anaconda2/lib/python2.7/site-packages/pandas/io/sql.pyc in read_sql(sql, con, index_col, coerce_float, params, parse_dates, columns, chunksize)
497 sql, index_col=index_col, params=params,
498 coerce_float=coerce_float, parse_dates=parse_dates,
--> 499 chunksize=chunksize)
500
501 try:
/home/mapr/anaconda2/lib/python2.7/site-packages/pandas/io/sql.pyc in read_query(self, sql, index_col, coerce_float, params, parse_dates, chunksize)
1598 args = _convert_params(sql, params)
1599 cursor = self.execute(*args)
-> 1600 columns = [col_desc[0] for col_desc in cursor.description]
1601
1602 if chunksize is not None:
TypeError: 'NoneType' object is not iterable
관련 코드가 보인다).
cnxn = pyodbc.connect(cnxn_str)
cursor = cnxn.cursor()
#Sample select query
print 'Testing db connection...'
cursor.execute("SELECT @@version;")
row = cursor.fetchone()
while row:
print row[0]
row = cursor.fetchone()
을 그리고 실제로 서버 버전을 받고 :
그 pyodbc을 확인할 수 있습니다 실행하여 바로 구성되어 있습니다.
왜 이런 일이 발생할 수 있고 수정하는 방법에 대한 아이디어가 있습니까? 감사.
DB-API는'.execute()'가 명령 하나당 하나의 쿼리 만 허용한다고 지정합니다. – bernie
@bernie - 방금 [PEP249] (https://www.python.org/dev/peps/pep-0249/)를 다시 한 번 보았습니다. 물론 익명 코드 블록 (다중 문장 일괄 처리) * ODBC 드라이버가 허용하는 경우 (SQL Server 용 Microsoft의 ODBC 드라이버가 허용하는 경우) * 작동 할 수 있습니다. –
아, 그래. 고맙습니다 @ GordThompson. 나는 그때 착각해야한다. – bernie