天天看點

PG将多個記錄值通過into設定給一個變量的時候,此時變量會取第一個值,不會報錯

drop table if exists test;
create table test(id int, name varchar);
insert into test select  n, n||'name' from generate_series(1,10) as t(n);


CREATE OR REPLACE FUNCTION func_test()
RETURNS INTEGER
AS
$BODY$
DECLARE
 tmp_name varchar;
BEGIN
    select name into tmp_name from test where id<10;
    raise notice 'tmp_name = %', tmp_name;
    RETURN 0;
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;
select * from func_test()      
  • 結果: