【发布时间】:2020-02-12 10:28:47
【问题描述】:
我是 postgresql 的新手,并创建如下函数
CREATE OR REPLACE FUNCTION GetLogs(
_from Date,
_to Date,
_sortBy TEXT,
_orderby INT,
_page INT,
_row INT)
RETURNS TABLE (
"Id" UUID,
"RequestHeaders" text,
"RequestContent" text,
"ResponseHeaders" text,
"ResponseContent" text,
"ResponseCode" integer,
"ExecutionTimeMs" integer,
"Description" text,
"RecordedOn" timestamp with time zone,
"Username" character varying,
"Exception" text)
AS $$
BEGIN
RETURN QUERY
SELECT COUNT(1)
FROM dbo."Logs" log
where log."RecordedOn" >= $1 and log."RecordedOn" <= $2;
RETURN QUERY
SELECT log.*
FROM dbo."Logs" log
where log."RecordedOn" >= $1 and log."RecordedOn" <= $2
Offset ($5-1) * $6
Limit $6;
END;
$$ LANGUAGE plpgsql;
,并使用
调用它select * from GetLogs('2020-02-11','2020-02-12','Date',0,1,10)
我希望这将是一个计数和表格数据,但错误是
ERROR: structure of query does not match function result type
DETAIL: Returned type bigint does not match expected type uuid in column 1.
有人能解决吗?
【问题讨论】:
-
第一个
RETURN QUERY仍然需要返回您定义该函数返回的结构。相反,您返回一个BIGINT。您希望从这个函数中得到什么格式?显示一个示例,其中包含您希望从函数调用中获得的输出。
标签: postgresql window-functions