I am trying trying to delete duplicates from Redshift table
Mycode
from sqlalchemy import create_engine
# A long string that contains the necessary Postgres login information
postgres_str = f'postgresql://{redshift_username}:{redshift_password}@{redshift_address}:{redshift_port}/{redshift_dbname}'
# Create the connection
cnx = create_engine(postgres_str)
delstatmt = '''WITH CTE AS
(
SELECT *,ROW_NUMBER() OVER (PARTITION BY org_country_code,dest_country_code,postcode,zone,kg,value,carrier,version
ORDER BY org_country_code,dest_country_code,postcode,zone,kg,value,carrier,version ) AS RN
FROM d.axis
)
DELETE FROM d.axis transformed WHERE RN<>1'''
cnx.execute(delstatmt)
Error
ProgrammingError: (psycopg2.errors.SyntaxError) syntax error at or near "DELETE"
LINE 8: DELETE FROM d.axis transformed WHERE ...
What is wrong is code. Any help appreciated.