Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support JSON column->path for quoteName #246

Open
Flowman opened this issue Mar 30, 2021 · 3 comments
Open

Support JSON column->path for quoteName #246

Flowman opened this issue Mar 30, 2021 · 3 comments

Comments

@Flowman
Copy link

Flowman commented Mar 30, 2021

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.

@nibra
Copy link
Contributor

nibra commented Mar 30, 2021

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.

@Flowman
Copy link
Author

Flowman commented Mar 30, 2021

Looks like they do.

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

@HLeithner
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants