SqlDelete
- class SqlDelete(table)
Builds a DELETE query. Created via
SQL.delete(table). Inherits fromSqlStatement(viaSqlQuery).- Parameters:
table – Target table name string.
In the examples below,
qbrefers to aSqlDeleteinstance: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(orNoneto 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
- returning(*items)
Add a RETURNING clause.
- Parameters:
items – One or more column name strings or
SqlObjinstances.
qb.returning('id', 'title') # RETURNING id, title
- recursive()
Mark the WITH clause as RECURSIVE.
- with_cte(cte)
Add a
SqlCteinstance to the WITH clause.- Parameters:
cte – A
SqlCteobject (created viaSQL.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
SqlQueryfor the CTE body.
qb.with_cte_query('old_tasks', select_query)