From: | XM <talkcc(at)163(dot)com> |
---|---|
To: | pgsql-bugs(at)postgresql(dot)org |
Subject: | help |
Date: | 2017-12-29 03:16:01 |
Message-ID: | 639e1dcf.48ee.160a044f47a.Coremail.talkcc@163.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
Hello
I use Dateframe to_sql to write records to a postgresql DB 9.6 , It can create the table 'Test_stock_basic_Info_2' ,but the records cannot be wrote into the table 'Test_stock_basic_Info_2'
the following is the code , is there any errors of the code ???
thanks for your help .
def testSQL():
import psycopg2
import pandas as pd
from sqlalchemy import create_engine
try:
engine = create_engine('postgresql+psycopg2://pub:pub(at)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 ...')
From | Date | Subject | |
---|---|---|---|
Next Message | Jeevan Chalke | 2017-12-30 07:13:20 | Re: [BUGS] BUG #14890: Error grouping by same column twice using FDW |
Previous Message | Bossart, Nathan | 2017-12-28 22:46:18 | Re: BUG #14941: Vacuum crashes |