1

I have this function:

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$

When executed, it shows this error:

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"

Why do I get this error, and how can I fix it?

Erwin Brandstetter
669k160 gold badges1.2k silver badges1.3k bronze badges
asked May 9, 2017 at 12:27
3
  • Apart from what Laurenz wrote, you are also missing the function body. Commented May 9, 2017 at 12:50
  • You also need to remove setof because RETURNS TABLE implies set and PostgreSQL will return error if you attempt to mix those. Commented May 9, 2017 at 13:54
  • 1
    What you show is not a function, only the header with a starting dollar quote, the rest obviously truncated. Please always present a complete (minimal) function - the one you actually have (minus possibly irrelevant stuff in the body). And always your version of Postgres. Commented May 9, 2017 at 14:16

2 Answers 2

3

It's either:

RETURNS TABLE (...)

or:

RETURNS SETOF sometype

You have an illegal mix of both forms. Looks like you replaced a double-quoted type name with a custom table definition. This would work:

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$;

Call:

SELECT * FROM pg_temp.sp_rptadvsalincr('a','b','c');

Details in the manual.

answered May 9, 2017 at 14:19
Sign up to request clarification or add additional context in comments.

Comments

0

Remove the double quotes around TABLE(...).

answered May 9, 2017 at 12:34

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.