昨天我们把PostgreSQL数据库升级到了9.1.3版本。我们以为我们已经测试并准备好了所有东西,但我们错过了一个功能。它返回如下表类型:
CREATE OR REPLACE FUNCTION myfunc(
patient_number varchar,
tumor_number_param varchar,
facility_number varchar
)
RETURNS SETOF patient_for_registrar
LANGUAGE plpgsql
AS
$body$
BEGIN
RETURN QUERY
SELECT cast(nfa.patient_id_number as varchar),
...
我只给出了select的第一列,因为这是错误发生的地方。在今天之前,此函数运行良好,但现在它出现了以下错误:
ERROR: structure of query does not match function result type
Detail: Returned type character varying does not match expected type character varying(8) in column 1. Where: PL/pgSQL function "getwebregistrarpatient_withdeletes" line 3 at RETURN QUERY [SQL State=42804]
列 有人有什么建议吗?nfa.patient_id_number
是文本,正在为patient_for_registrar
中的列
patient_it_number
转换,即varchar(8)
substring(cast(nfa.patient_id_number as varchar) from 1 for 8),
cast(substring(nfa.patient_id_number from 1 for 8) as varchar),
cast(substring(nfa.patient_id_number from 1 for 8) as varchar(8)),