以下の内容はhttps://yohei-a.hatenablog.jp/entry/20250104/1735968454より取得しました。


psql でコマンドラインから変数を渡して SQL 内で参照する

psqlコマンドラインから変数を渡して SQL 内で参照する方法。

  • -v オプションで変数を渡し、
psql -v query_id=54321 ...
  • SQL 内では :変数名 で渡された変数を参照する。
select * from SVL_QUERY_METRICS_SUMMARY where query = :query_id;

参考

-v assignment
--set=assignment
--variable=assignment
Perform a variable assignment, like the \set meta-command. Note that you must separate name and value, if any, by an equal sign on the command line. To unset a variable, leave off the equal sign. To set a variable with an empty value, use the equal sign but leave off the value. These assignments are done during command line processing, so variables that reflect connection state will get overwritten later.

PostgreSQL: Documentation: 17: psql



以上の内容はhttps://yohei-a.hatenablog.jp/entry/20250104/1735968454より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14