1

This query is working directly in Mysql:

SELECT entity_id FROM node__field_json WHERE JSON_EXTRACT(field_json_value, "$.mpk") = '014005'

I cannot make it working in Drupal:

$query = 'SELECT entity_id FROM node__field_json WHERE JSON_EXTRACT(field_json_value, "$.mpk") = :symbol';
$result = $this->database->query($query, [':symbol' => '014005'])->execute();

An error:

SQLSTATE[42S22]: Column not found: 1054 Unknown column '$.mpk' in 'where clause': SELECT entity_id FROM node__field_json WHERE JSON_EXTRACT(field _json_value, "$.mpk") = :symbol; Array
(

  [:symbol] => 014005                                                                                                                               > )
  • 1
    Have you tried single quotes around $.mpk? – Clive Jan 7 at 12:27
  • @Clive thanks a lot working, but only when I put variable in SQL string, so I cannot use :param anymore – Codium Jan 7 at 18:27

Your Answer

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

Browse other questions tagged or ask your own question.