LoginSignup
2
0

More than 1 year has passed since last update.

PL/pgSQLでSelectした結果のRecord Typeから値を変数に格納する

Last updated at Posted at 2021-10-25

PL/pgSQLではプログラムを書けることは分かったがSQLとの橋渡しがあまりわからなかったのでメモ
select hoge into v_hogeしてあげるとv_hogeに格納できる(筆者はsupabaseのfunction機能で動作確認しました)

例ではselect count(*)の結果をinteger型の変数cntに格納する

DECLARE
  cnt integer;
BEGIN
  select count(*)
    into cnt
    from table_name
    where col1 = 1;
  RETURN cnt;
END
2
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
2
0