Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem
PDOException: Integrity constraint violation: 1052 Column 'changed' in field list is ambiguous.
To reproduce:
-
Content translation
- enable Content translation (translation) module
- enable entity_translation module
- create a Relevant Content Block with
- Display Options -> Order on -> select 'Any date option' OR with Filter Options -> Date Filter -> select 'Yes'
- Filter Options -> Translation -> "Filter on user's language" selected
- view the block
SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'changed' in field list is ambiguous:
SELECT node.nid AS entity_id, node.vid AS revision_id, node.type AS bundle, node.language AS language,
et.language AS et_language, et.status AS et_status, et.translate AS et_translate, :entity_type AS entity_type,
CASE node.type WHEN 'page' THEN changed
WHEN 'restricted_page' THEN created
WHEN 'webform' THEN created
WHEN 'building' THEN created
WHEN 'channel_event' THEN created
WHEN 'channel_news' THEN created
WHEN 'mprofile' THEN created
WHEN 'media_gallery' THEN created
WHEN 'campus' THEN created
ELSE '' END
AS sort_date
FROM {node} node
LEFT OUTER JOIN {entity_translation} et ON et.entity_type = :base_table
AND et.entity_id = node.nid
AND et.language = :language
WHERE (node.nid <> :db_condition_placeholder_0)
AND (node.status = :db_condition_placeholder_1)
AND (node.type IN (:db_condition_placeholder_2))
AND( (node.language = :db_condition_placeholder_3) OR (node.language = :db_condition_placeholder_4) O( (et.language = :db_condition_placeholder_5)
AND (et.status = :db_condition_placeholder_6) ))
ORDER BY sort_date ASC
LIMIT 10 OFFSET 0;
in EntityFieldQuery->execute() (line 1216 of /srv/wpslabs/drupal7/includes/entity.inc).
This error occurs because both the node and the entity_translation tables have a 'changed' column.
Proposed resolution
Add table name to select fields to avoid ambiguity.
Comment | File | Size | Author |
---|---|---|---|
#5 | bean_relevant-pdoexception_lang_filter-2801493-5.patch | 1.91 KB | karolinam |
Comments
Comment #2
karolinam CreditAttribution: karolinam commentedComment #3
karolinam CreditAttribution: karolinam commentedComment #4
karolinam CreditAttribution: karolinam commentedComment #5
karolinam CreditAttribution: karolinam commentedAdding a fix for filtering by date.