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?

初めに

Qiita Engineer Festa 2024に参加中。完走目指してます。
他のメタコマンドについては以下から読んでください。

\setとは

psqlの変数namevalue、または複数のvalueが与えられた場合はそれらを連結したものに設定します。 第一引数しか指定されない場合は、変数に空文字列の値が設定されます。 変数を未設定とするには、\unsetコマンドを使用してください。

引数をまったく取らない\setは、現在設定されているpsql変数すべての名前と値を表示します。

変数名には、文字、数字、アンダースコアを使用することができます。 詳細は、後述の変数を参照してください。 変数名は大文字小文字を区別します。

psqlの動作を制御する、あるいは接続状態を表す値に自動的に設定される、という点で特別な変数がいくつかあります。

\setについて

試してみた

postgres=# \set myvar 'Alice'
postgres=# select * from employees where name = :'myvar';
 id | name  | department | salary 
----+-------+------------+--------
  1 | Alice | HR         |  60000
(1 )

まとめ

手動実行するときにバインド変数として活用しています。

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?