SqlDelete

class SqlDelete(table)

Builds a DELETE query. Created via SQL.delete(table). Inherits from SqlStatement (via SqlQuery).

Parameters:

table – Target table name string.

In the examples below, qb refers to a SqlDelete instance:

qb = SQL.delete('films')
only()

Add ONLY keyword to restrict to the named table (no inherited tables).

qb.only()
# DELETE FROM ONLY films
using(table)

Add a USING clause. Can be called multiple times for multiple tables.

Parameters:

table – Table name string or expression.

qb.using('producers')
# USING producers
where(*expr)

Set the WHERE clause. Accepts either a single SqlObj (or None to clear), or positional args (expr, op, value) which are wrapped in a SqlTerm. See SqlTerm for the full list of supported parameter variants.

qb.where('kind', '<>', 'Musical')
# sql:       WHERE kind <> %s
# args:      ['Musical']
# mogrified: WHERE kind <> 'Musical'

qb.where('employees.id = accounts.sales_person')
# WHERE employees.id = accounts.sales_person
get_where()

Returns the current WHERE expression, or None.

Return type:

SqlObj or None

returning(*items)

Add a RETURNING clause.

Parameters:

items – One or more column name strings or SqlObj instances.

qb.returning('id', 'title')
# RETURNING id, title
recursive()

Mark the WITH clause as RECURSIVE.

with_cte(cte)

Add a SqlCte instance to the WITH clause.

Parameters:

cte – A SqlCte object (created via SQL.cte()).

qb.with_cte(SQL.cte('helper', helper_query))
with_cte_query(alias, query)

Shorthand for adding a CTE.

Parameters:
  • alias – CTE name string.

  • query – A SqlQuery for the CTE body.

qb.with_cte_query('old_tasks', select_query)