def testSQL(): import psycopg2 import pandas as pd from sqlalchemy import create_engine
try:
engine = create_engine('postgresql+psycopg2://pub:pub@localhost/Wind_Quote')
#conn=engine.raw_connection()
#cur = conn.cursor()
df = pd.DataFrame()
df['stock_code']='0000'
df['ipo_date'] ='2015-01-07'
df['sec_name'] ='11111111'
df['trade_code'] ='22222222222'
try :
df.to_sql(name='Test_stock_basic_Info_2', con=engine,if_exists='replace',index=False)
#conn.commit()
#cur.execute('COMMIT')
except Exception as e:
print ( time.strftime('At [%Y-%m-%d %H:%M:%S]', time.localtime(time.time())),": index_data: Exception :" , (e) )
except Exception as e:
print ( time.strftime('At [%Y-%m-%d %H:%M:%S]', time.localtime(time.time())),": program: Exception :" , (e) )
print('Finished ...')
##########################################################
I use Dateframe to_sql to write records to a postgresql DB , It can create the table 'Test_stock_basic_Info_2' ,but the records cannot be wrote into the table 'Test_stock_basic_Info_2'
no exception , is there any errors of the code ???
postgresql version 9.5.10-2-windows
thanks for your help .
Comment From: teeger
anyone can help me ?
Comment From: gfyoung
@teeger : Thanks for the issue! Unfortunately, your issue is hard to reproduce because we can't just access the SQL server that you included in code. Secondly, the fact that there is no error message means that the code probably didn't break AFAICT, but rather that there is something fishy with your database.
I would have a look there to see if there's anything problematic. At this point, I think pandas
is in the clear unless further information is provided to show otherwise.
Comment From: dmoliveira
The issue is still happening. You can simulate using his code using any Postgres (docker environment)... It would help many people if someone investigated. I found this:
https://stackoverflow.com/questions/48307008/pandas-to-sql-doesnt-insert-any-data-in-my-table