LoginSignup
38
34

More than 5 years have passed since last update.

re:dashでsqlに変数を埋め込む

Last updated at Posted at 2015-07-13

ドキュメントにはどこにも書いておらず、githubのissueにちょこっと書いてあるだけだったのでメモしときます。

sqlを書く

select id from users where id = {{id}}
  • {{id}}が今回変数を埋め込む部分です。
  • template言語はmustacheです

エラーにはなりますが気にせずクエリを保存します。

アクセスする

query_stringを以下のようにしてアクセスします

http://${redashのhost名}/queries/${queryのID}?p_id=1
  • 「p_」を先頭に追加した変数の値がsqlに埋め込まれて結果が返ってきます
  • 「{{name}}」などを埋め込んでいる場合は「p_name=1」にしてアクセスします

id = 1 のrecordの結果が返ってきました。

ダッシュボードでも

ダッシュボードでも同じルールで使えます。

http://${redashのhost名}/dashboard/${dashboard名}?p_id=1

注意点

  • 実行結果のキャッシュがされにくい。(同じ変数であれば実行されるsqlは同じなのでキャッシュは効く)

まとめ

  • アプリケーションからre:dashにリンクを張るといった用途に使える!
38
34
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
38
34