On this page
MySQLism and PostgreSQLism: DELETE on JOINS requires the USING syntax
Drupal 7 will no longer be supported after January 5, 2025. Learn more and find resources for Drupal 7 sites
SQL-99 does not allow to delete data in a table when using JOINS. The reasons for this are quite obscure. Maybe it was considered too complicated to implement. Therefore for safety reasons it was not part of the standard.
As a result, MySQL implemented this feature and PostgreSQL rejected it.
The following query works under MySQL but fails under PostgreSQL:
DELETE h
FROM history AS h
INNER JOIN term_node AS tn ON (h.nid = tn.nid)
INNER JOIN term_data AS td ON (td.tid = tn.tid)
WHERE h.uid = 2067 AND td.vid = 2
A solution may be to write:
DELETE
FROM history AS h
USING term_node AS tn, term_data AS td
WHERE (h.nid = tn.nid) AND (td.tid = tn.tid) AND h.uid = 2067 AND td.vid = 2
USING is not part of SQL-99, but it is supported by most databases, including MySQL and PostgreSQL.
References:
#459384: PostgreSQL does not allow nested DELETE queries
#337687: PostgreSQL support
#1079620: DELETE FROM ... INNER JOIN is by convention not allowed in Drupal
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion