pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: XM <talkcc@163.com>
To: pgsql-bugs@postgresql.org
Subject: help
Date: Fri, 29 Dec 2017 11:16:01 +0800 (CST)
Message-ID: <639e1dcf.48ee.160a044f47a.Coremail.talkcc@163.com> (raw)

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@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  ...')




 

view thread (38+ messages)  latest in thread

Message-ID: <639e1dcf.48ee.160a044f47a.Coremail.talkcc@163.com>
Permalink:  ../639e1dcf.48ee.160a044f47a.Coremail.talkcc@163.com/
Also on:    postgresql.org/message-id/639e1dcf.48ee.160a044f47a.Coremail.talkcc@163.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: talkcc@163.com
  Subject: Re: help
  In-Reply-To: <639e1dcf.48ee.160a044f47a.Coremail.talkcc@163.com>
  References: <639e1dcf.48ee.160a044f47a.Coremail.talkcc@163.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox