CData Python Connector for Greenplum

Build 21.0.7930

Batch Processing

This python connector is also able to perform batch processing to write to the data source. This can be done by using the executemany() method of the cursor object. In addition to a SQL statement string, a data frame of values should be provided as a series of parameters to execute the SQL statement with. as with normal write operations, the statements are executed immediately by the provider. Do not call the connection's commit() method following the execution.

Insert

The following example adds new records to the table:

cur = conn.cursor()
cmd = "INSERT INTO \"template1\".\"public\".Orders (ShipName, ShipCity) VALUES (?, ?)"
params = [["Raleigh", "New York"], ["Raleigh", "New York"]]
cur.executemany(cmd, params)
print("Records affected: ", cur.rowcount)

Update

The following example modifies existing records in the table:

cur = conn.cursor()
cmd = "UPDATE \"template1\".\"public\".Orders SET ShipCity = ? WHERE Id = ?"
params = [["New York", "10261"], ["New York", "10261"]]
cur.executemany(cmd, params)
print("Records affected: ", cur.rowcount)

Copyright (c) 2021 CData Software, Inc. - All rights reserved.
Build 21.0.7930