0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

metabase&mysqlの環境でgroup_concatの文字数制限をどうにかする方法

Posted at

mysqlのgroup_concatにまつわる制限

mysqlには集合関数でgroup_concatという任意のセパレーターで文字列を集計できるという便利な関数があります。
ただしこの関数には結合後の文字数が制限されており、デフォルトの1024文字を超えさせたい場合には、my.cnfでDBの設定を変えるか、セッション内でSET SESSION group_concat_max_len = 4194304; と入れるようにして制限を解除する必要があります。

metabaseは複数ステートメントのSQL実行をサポートしていない。

以下のIssueで管理されていますが、6年以上Openでおそらく今後もサポートされなさそうな状態です。
https://github.com/metabase/metabase/issues/4050

ではどうするか。

そして、GROUP_CONCATの列が尻切れになる問題の対処が必要になったらどうするか。

大前提

  • my.cnfで対応できるならばそれで対応すべき。

JDBCへのパラメーターで対応する。

前述のIssueで取り上げられている対応ですが、metabaseのDB接続設定の高度な設定でJDBCパラメーターを設定することで対応ができます。

https://github.com/metabase/metabase/issues/4050#issuecomment-927185845
https://stackoverflow.com/questions/26425045/how-to-pass-session-variables-in-jdbc-url-properly

sessionVariables=group_concat_max_len=4194304

image.png

無論全てのクエリ実行に影響するので、レスポンスの影響など加味する必要はありますが、これで解決です。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?