I'm trying to parse an API response which is in json format to a tabular format and write the same to a table residing on Microsoft SQL server.
Each json api response has 51 columns and there are around 15 million rows of data to be written to the SQL server.
I have tried combinations of pyodbc and sqlalchemy as mentioned in other posts on SO.
Using the traditional SQL "insert into " involves hitting the database millions of times which doesn't seem right.
My current Pandas version - 0.14+, Python version 2.7.9
I get the following error when I try to write a sample data frame to the sql table on Continuum.io's wakari server.
sqlalchemy.exc.ResourceClosedError: This result object does not return rows. It has been closed automatically.
When I run the same locally, the following error is being returned:
pyodbc.ProgrammingError: ('42S02', "[42S02] [Microsoft][SQL Server Native Client 11.0][SQL Server]Invalid object name 'sqlite_master'. (208) (SQLExecDirectW)")
Following is the code:
import sqlalchemy
import pyodbc
import pandas as pd
from pandas.io.sql import frame_query
from sqlalchemy import create_engine
engine = create_engine('mssql+pyodbc://<userid>:<password>@pydsn')
cnxn = engine.raw_connection()
df = pd.DataFrame()
data = pd.DataFrame({"A": range(9),"B":range(9)})
df = df.append(data)
print df
df.to_sql("dbo.xyz_test",cnxn,if_exists = 'replace')
print 'done'
Appreciate any help here.