首页 文章

包含查询“Select * from table name”的plpgsql函数

提问于
浏览
-1

我想创建一个plpgsql函数,它将执行一个简单的选择查询,即 . “从表名中选择*” . 当我通过此查询运行该函数时,就像“select function()”一样,它将输出为“Select * from table name” .

1 回答

  • 0

    不需要PL / pgSQL功能 . 一个简单的SQL函数将:

    create or replace function get_result()
      returns setof table_name
    as
    $$
      select * from table_name;
    $$
    language sql;
    

    但是你需要使用 select * from function(); 来获得结果 not select function() ,因为set returns函数只能在 from 子句中使用 .

相关问题