You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
IF OBJECT_ID('tempdb..#tmp') IS NOT NULL DROP TABLE #tmp;select*
into #tmp fromfin.dbo.items_info
IF OBJECT_ID('tempdb..#test1') IS NOT NULL DROP TABLE #test1;selectt.PositionID, b.SecurityID
into #test1from#tmp as tinner joinfin.dbo.items as b on (b.PositionID=t.PositionIDandb.StudyDate='20191230')
wheret.ast='eq';
IF OBJECT_ID('tempdb..#beta_index') IS NOT NULL DROP TABLE #beta_index;select distinct isin, beta_index into #beta_index from md.data.equity;
IF OBJECT_ID('tempdb..#test2') IS NOT NULL DROP TABLE #test2;selectt.PositionID,
case
when count(i.beta_index)=0 then 1
else count(i.beta_index)
end as noIndex
into #test2 from#test1 as t left join#beta_index as i on (t.SecurityID = i.isin)group byt.PositionID;
select*from#test2
Problem description
I am trying to get a dataframe from the above query, however it throws TypeError: 'NoneType' object is not iterable when trying to pull results from #test2 table ('SET NOCOUNT ON;' is being used) . Everything up to that point and after works perfectly, however it looks like it has something to do with counting and grouping. I can pull #test1 table above just fine. No issues with other lengthy queries with insert, update, group though.
Additionally, this query works fine when running it in SSMS v18.4 (using it as a driver).
Expected Output
I expect to get an output from #table2 table. The select statement should return a non empty table (which it does in SSMS).
Output of pd.show_versions()
INSTALLED VERSIONS
commit : None
python : 3.7.6.final.0
python-bits : 64
OS : Windows
OS-release : 10
machine : AMD64
processor : Intel64 Family 6 Model 78 Stepping 3, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.None
I have tried connecting to db manually with pyodbc and fetching the table - it seems to throw "ProgrammingError: No results. Previous SQL was not a query." when fetching #test2, but works when fetching #test1. Looks like it is a pyodbc issue.
I found the solution to my problem, so just in case someone else runs into this issue, here's my comment from pyodbc ticket:
So I just realized that I was ignoring/disregarding warning messages in SSMS, which, I believe, results in cursor not being a query and pyodbc throwing ProgrammingError "No results. Previous SQL was not a query."
The warning:
Warning: Null value is eliminated by an aggregate or other SET operation.
SET ANSI_WARNINGS OFF solved the issue.
Inserting "SET ANSI_WARNINGS OFF" at the beginning of SQL query worked.
Code Sample, a copy-pastable example if possible
SQL part
Problem description
I am trying to get a dataframe from the above query, however it throws TypeError: 'NoneType' object is not iterable when trying to pull results from #test2 table ('SET NOCOUNT ON;' is being used) . Everything up to that point and after works perfectly, however it looks like it has something to do with counting and grouping. I can pull #test1 table above just fine. No issues with other lengthy queries with insert, update, group though.
Additionally, this query works fine when running it in SSMS v18.4 (using it as a driver).
Expected Output
I expect to get an output from #table2 table. The select statement should return a non empty table (which it does in SSMS).
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : None
python : 3.7.6.final.0
python-bits : 64
OS : Windows
OS-release : 10
machine : AMD64
processor : Intel64 Family 6 Model 78 Stepping 3, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.None
pandas : 0.25.3
numpy : 1.18.1
pytz : 2019.3
dateutil : 2.8.1
pip : 20.0.2
setuptools : 41.2.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.4.2
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : 7.11.1
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : 4.4.2
matplotlib : 3.1.2
numexpr : None
odfpy : None
openpyxl : 3.0.3
pandas_gbq : None
pyarrow : None
pytables : None
s3fs : None
scipy : 1.4.1
sqlalchemy : None
tables : None
xarray : None
xlrd : 1.2.0
xlwt : None
xlsxwriter : None
The text was updated successfully, but these errors were encountered: