I am getting some unusual text which is getting added to my queries in views. I am referring to the part setting view_name.

SELECT users.name AS users_name, users.uid AS uid, 'cardinality_user_test:page' AS view_name
{users} users
LEFT JOIN {node} node_users ON (SELECT nodeINNER.nid AS nidINNER, ':default' AS view_name
{node} node INNER LEFT JOIN {users} users_nodeINNER ON nodeINNER.uid = users_nodeINNER.uid
WHERE (( (users_nodeINNER.uid = users.uid ) ))
LIMIT 1 OFFSET 0) = node_users.nid

This additional SQL is creating an error:

SQLSTATE[21000]: Cardinality violation: 1241 Operand should contain 2 column(s)

What is causing that text to be added in Drupal 7?


That extra field is added from the Views module itself, in particular its views_plugin_query_default::add_signature() method, which is described as:

Add a signature to the query, if such a thing is feasible.
This signature is something that can be used when perusing query logs to discern where particular queries might be coming from.

If you look at its code, it is setting the view_name field.

function add_signature(&$view) {
  $view->query->add_field(NULL, "'" . $view->name . ':' . $view->current_display . "'", 'view_name');
  • Thank you. From your answer I realised I had ticked "Add Views signature to all SQL queries" in the Advanced Views Settings which was causing an error in some of my views. – Ben Mar 27 '17 at 15:41
  • Yes, I should add that in the answer. Understanding which setting is causing that view's behavior is not immediate. – kiamlaluno Mar 27 '17 at 19:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.