Postgresql Postgres存储函数如何返回表

Postgresql Postgres存储函数如何返回表,postgresql,function,return,Postgresql,Function,Return,我想了解Postgres存储函数如何返回具有已标识列的表。我使用了returnType的returns集合: -- create employeeSearchResult returnType create type employeeAllReturnType as ( id bigserial, "positionId" integer, "subjectId" bigint, "dateEngaged" date, "nextKin" text, "nrcNo" te

我想了解Postgres存储函数如何返回具有已标识列的表。我使用了returnType的returns集合:

-- create employeeSearchResult returnType
create type employeeAllReturnType as
(
  id bigserial,
  "positionId" integer,
  "subjectId" bigint,
  "dateEngaged" date,
  "nextKin" text,
  "nrcNo" text,
  dob date,
  father text,
  mother text,
  wife text,
  "userId" integer,
  "statusId" integer,
  "mainCode" text,
  "subCode" text
);


-- Search for emmployee by name
CREATE OR REPLACE FUNCTION "employee_search_by_name"(employeeNameIN text)
returns setof employeeAllReturnType as 
$$
declare
    results record;
    resultsRow employee%rowtype;
    nameIn text;
begin
    nameIn = employeeNameIN || '%';
    for results in select 
        employee.id,-- bigserial NOT NULL,
  employee."positionId",-- integer,
  employee."subjectId",-- bigint NOT NULL,
  employee."dateEngaged",-- date,
  employee."nextKin",-- text,
  employee."nrcNo",-- text,
  employee.dob,-- date,
  employee.father,-- text,
  employee.mother,-- text,
  employee.wife,-- text,
  employee."userId",-- integer NOT NULL,
  employee."statusId",-- integer,
  employee."mainCode",-- character(5) NOT NULL,
  employee."subCode"-- character(10),
     from employee, subject where employee."subjectId" = subject.id and (subject.name1 ILIKE nameIn OR subject.name2 ILIKE nameIn OR subject.name3 ILIKE nameIn OR subject.name4 ILIKE nameIn) loop
      return next results;
    end loop;
end;
$$ language 'plpgsql';
并返回表():

但两者都有以下格式的输出:

"(1,1,1,2011-12-01,Timea,fg1254,1981-12-27,moses,sarada,timea,1,1,"ADM  ","1         ")"
"(37,3,10,2011-11-11,s,s,2011-11-11,s,s,s,1,1,"OP   ","1         ")"
是否有任何输出,例如从表中选择结果的输出

"1";1;1;"2011-12-01";"Timea";"fg1254";"1981-12-27";"moses";"sarada";"timea";1;1;"ADM  ";"1         "

这样处理前端的结果数据就不需要解析器。

您应该像这样查询函数:

按姓名(“Bob”)从员工搜索中选择*;

此外,为了简化您的函数,您可以查看构造。无需引用
plpgsql
关键字。

无需在此处使用双引号。请检查下面的答案
"1";1;1;"2011-12-01";"Timea";"fg1254";"1981-12-27";"moses";"sarada";"timea";1;1;"ADM  ";"1         "