【发布时间】:2017-07-15 22:45:40
【问题描述】:
我收到此错误:
ERROR: structure of query does not match function result type DETAIL: Returned type information_schema.sql_identifier does not match expected type character varying in column 1. CONTEXT: PL/pgSQL function app.get_custom_task_fields(integer,character varying,integer) line 10 at RETURN QUERY
要修复它,我需要在查询中知道column_name、ordinal_position 和data_type 的类型。或者更一般地说,information_schema.columns 中列的数据类型是什么?如何将 sql_identifier 转换为“可输出”格式以将其从我的函数中取出?
这是我的功能:
CREATE OR REPLACE FUNCTION app.get_custom_task_fields(sess_identity_id int
,session_code_str varchar
,sess_company_id int)
RETURNS TABLE(field_name varchar,ordinal_position integer,field_type varchar)
AS $$
DECLARE
BEGIN
RETURN QUERY
SELECT t.column_name,t.ordinal_position,t.data_type
FROM INFORMATION_SCHEMA.COLUMNS as t
WHERE table_name = 'task_custom' order by t.ordinal_position;
END;
$$ LANGUAGE PLPGSQL;
【问题讨论】:
-
您忘记提供您的 Postgres 版本 (
SELECT version();)。
标签: postgresql types plpgsql information-schema