我有这个功能:
CREATE OR REPLACE FUNCTION public.sp_rptadvsalincr(
p_flag character,
p_empcds character varying,
p_incrtype character varying)
RETURNS SETOF "TABLE(empcd character, name character varying, basic integer, incrdt timestamp without time zone, incrdbasic integer, nextincrdt timestamp without time zone, deptgenno character varying)"
LANGUAGE 'plpgsql'
COST 100.0
VOLATILE NOT LEAKPROOF
ROWS 1000.0
AS $function$
执行时,会显示以下错误:
ERROR: type "TABLE(empcd character, name character varying, basic integer, i" does not exist
NOTICE: identifier "TABLE(empcd character, name character varying, basic integer, incrdt timestamp without time zone, incrdbasic integer, nextincrdt timestamp without time zone, deptgenno character varying)" will be truncated to "TABLE(empcd character, name character varying, basic integer, i"
为什么我会收到此错误,我该如何解决?
答案 0 :(得分:3)
它是:
RETURNS TABLE (...)
或:
RETURNS SETOF sometype
你有两种形式的非法混合。看起来您用自定义表定义替换了双引号类型名称。这可行:
CREATE OR REPLACE FUNCTION public.sp_rptadvsalincr(
p_flag character,
p_empcds character varying,
p_incrtype character varying)
RETURNS TABLE(empcd character, name character varying, basic integer, incrdt timestamp without time zone, incrdbasic integer, nextincrdt timestamp without time zone, deptgenno character varying)
LANGUAGE plpgsql
COST 100
VOLATILE NOT LEAKPROOF
ROWS 1000
AS $function$
BEGIN
RETURN QUERY
SELECT NULL::char, NULL::varchar, NULL::int, NULL::timestamp, NULL::int, NULL::timestamp, NULL::varchar;
END
$function$;
呼叫:
SELECT * FROM pg_temp.sp_rptadvsalincr('a','b','c');
答案 1 :(得分:0)
删除TABLE(...)
附近的双引号。