database icon indicating copy to clipboard operation
database copied to clipboard

Support JSON column->path for quoteName

Open Flowman opened this issue 4 years ago • 3 comments

Just want to check if there is any plan to support MySQL JSON column->path for quoteName function.

https://dev.mysql.com/doc/refman/5.7/en/json-search-functions.html#operator_json-column-path

Something like:

$db->quoteName('params->"$.field"', 'as_field');

It should only quote the "params" part.

Flowman avatar Mar 30 '21 15:03 Flowman

This would be possible only, if either PostgreSQL supports that, too, or we can (want to) mimic that for PostgreSQL. I'm not very much into that subject, so I leave this open for a day or so to allow posting hints.

nibra avatar Mar 30 '21 20:03 nibra

Looks like they do.

https://www.postgresqltutorial.com/postgresql-json/

Flowman avatar Mar 30 '21 23:03 Flowman

Doesn't sound like a good idea, quoting functions shouldn't be to complex. It would be better to have an own constructor for such queries that can build a proper field statement.

Maybe looking at other database layers how this is handled.

Out of the blue have something like

function quoteJsonAsJson($field, $elements =[], $as='') {
  return $this->quoteName($field).' -> '.  implode('->', $this->quote($elements)) . ' AS ' . $as;
}

function quoteJsonAsText($field, $elements =[], $as='') {
  $last = array_pop($elements);
  return $this->quoteJsonAsJson($field, $elements) .' ->>' . $last . ' AS ' . $as;
}

function quoteJsonAsType($type, $field, $elements =[], $as='') {
  $last = array_pop($elements);
  switch($type) {
    case ParameterType::INTERGER:
      $type = 'INTEGER';
    ....
  } 
  return 'CAST(' . $this->quoteJsonAsText($field, $elements) . ') AS ' . $as;
}

That's just a short idea, nothing detail maybe others solved this in a much better or more generic/specific way.

HLeithner avatar Sep 27 '21 16:09 HLeithner