Delete data from teradata using pyspark

589 Views Asked by At

I am trying to delete the record from teradata and then write into the table for avoiding duplicates So i have tried in many ways which is not working

  1. I have tried deleting while reading the data which is giving syntax error like '(' expected between table and delete spark.read.format('jdbc').options('driver','com.TeradataDriver').options('user','user').options('pwd','pwd').options('dbtable','delete from table').load()

Also tried like below, which is also giving syntax error like something expected between '('and delete options('dbtable','(delete from table) as td')

2)I have tried deleting while writing the data which is not working

df.write.format('jdbc').options('driver','com.TeradataDriver').options('user','user').options('pwd','pwd').options('dbtable','table').('preactions','delete from table').save()

1

There are 1 best solutions below

0
On

Possible solution is to call procedure which delete data.

import teradata

host,username,password = '','', ''
udaExec = teradata.UdaExec (appName="test", version="1.0", logConsole=False)

with udaExec.connect(method="odbc"
                     ,system=host
                     ,username=username
                     ,password=password
                     ,driver="Teradata Database ODBC Driver 16.20"
                     ,charset= 'UTF16'
                     ,transactionMode='Teradata') as connect:

    connect.execute("CALL db.PRC_DELETE()", queryTimeout=0)