New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DELETE statement for Redshift Dialect #35

haleemur opened this Issue Sep 2, 2015 · 0 comments


None yet
1 participant

haleemur commented Sep 2, 2015

Redshift's delete statement varies slightly from Postgresql's. See here for documentation.

Basic delete statements have the same syntax.

For instance, the following is valid SQL in both dialects:

DELETE FROM customer_table WHERE > 1000

However, while the following is a valid statement in Postgresql:

DELETE FROM customer_table 
WHERE = order_table.customer_id 
AND < 100

It needs to be written for Redshift as:

DELETE FROM customer_table
USING order_table
WHERE = order_table.customer_id
AND < 100

SqlAlchemy should be able to build this resultant query with the following Python snippet:

from sqlalchemy import delete, Table, Column, Integer, MetaData
from redshift_sqlalchemy import RedshiftDialect
meta = MetaData()
customer = Table('customer_table', meta, Column('id', Integer, primary_key=True))
order = Table('order_table', meta, Column('id', Integer, primary_key=True), Column('customer_id', Integer)
del_stmt = delete(order).where(<100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment