Store query result in a variable using in PL/pgSQL

前端 未结 5 1361
别那么骄傲
别那么骄傲 2020-11-29 21:12

How to assign the result of a query to a variable in PL/pgSQL, the procedural language of PostgreSQL?

I have a function:

CREATE OR REPLACE FUNCTION t         


        
5条回答
  •  佛祖请我去吃肉
    2020-11-29 21:42

    The usual pattern is EXISTS(subselect):

    BEGIN
      IF EXISTS(SELECT name
                  FROM test_table t
                 WHERE t.id = x
                   AND t.name = 'test')
      THEN
         ---
      ELSE
         ---
      END IF;
    

    This pattern is used in PL/SQL, PL/pgSQL, SQL/PSM, ...

提交回复
热议问题