1 year ago

#372996

test-img

Janet

How do you mass insert data from one table to another using cx_oracle when one of the fields is of type sdo_geomentry

I am trying to do in python mass insert of data from one table to another where one of the fields is an oracle SDO_GEOMETRY(2001,4283,MDSYS.SDO_POINT_TYPE(X,Y ,NULL),NULL,NULL) using the cx_oracle library. I do have null values for this field. Is there a way to do this?

I have tried

  1. reading the data from the source table into a pandas dataframe,
  2. create an insert statement for the oracle cx_cursor where the variable for the value for the field is the column name in the pandas dataframe
  3. insert using cur.executemany(sql,df.to_dict('records')) where sql is the sql staement and df is the dataframe of values to insert converted to a dictionary and the cur is the cx_oracle cursor

When you read the data in as a pandas dataframe and change the field to be of type object and then change the null fields to None using the clearNaN function below this seems to work, but only up to 100,000 rows and you have to have one row that is not null

def clearNaNs(self,df):
    # this deals with NaN's in the dataframe which can not be inserted properly into an oracle dataframe.  it has to be changed to None
    df = df.astype(object)
    df.where(pd.notnull(df), None, inplace = True)
    return df

python

cx-oracle

0 Answers

Your Answer

Accepted video resources