ANANDA KRISHNAN
ANANDA KRISHNAN

Reputation: 79

Join clause in delete query with squirrel/PostgreSQL

I'm using the squirrel (github.com/Masterminds/squirrel) statement builder tool and Postgres DB.

Vendor and Vendor_Location are the two tables we have. Both tables are linked by the vendor_no attribute.

I need to delete information from Vendor Location that is no longer active. I need to delete data from location by joining them together; this can be done with the following SQL:

DELETE FROM vendor_location vl
        USING vendor v
    WHERE vl.vendor_no=v.vendor_no and v.last_login_date >= 'date';

Delete statement builder doesn't has a join function so I have implemented the query as:

squirrel.Delete("vendor_location vl").
Suffix("USING vendor v WHERE vl.vendor_no=v.vendor_no and v.last_login_date >= $1", date)

Please let me know if there is another option by using the same query builder tool.

Upvotes: 1

Views: 821

Answers (0)

Related Questions