1

I am using the following code to query an ECK entity.

$query = \Drupal::database()->select('object__field_amount', 'f');
$query->fields('f', array('object__field_amount_value'));
$query->addExpression('MAX(object__field_amount_value)', 'maxvalue');
$query->execute()->fetchAssoc();

It raises the following exception.

Drupal\Core\Entity\EntityStorageException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'maxvalue FROM object__field_amount f'

I've tried multiple other options, without result.

How do I avoid the code raises an exception?

1 Answer 1

3

MAXVALUE is a reserved word in MySQL (Maria). Change maxvalue to topvalue or something else.

2
  • Yes, MAXVALUE is the issue here. I think you can remove the "looks like". :-)
    – mradcliffe
    Commented Dec 27, 2016 at 14:15
  • Dear god, this was it, would have probably never found it myself. Thanks!
    – pjcarly
    Commented Dec 27, 2016 at 14:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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