Kwannon
Kwannon

Reputation: 15

How could I return a varchar message in Postgres as part of function return table that isn't in any table?

I need to return a message (a different message according some evaluations inside de function), but when I call the function it returns this error message: "Returned type unknown does not match expected type character varying in column 2".

CREATE OR REPLACE FUNCTION myfunction()RETURNS TABLE(
cod INTEGER,
 answ CHARACTER VARYING
 ) AS $BODY$
 BEGIN
 RETURN QUERY
    select 0, 'here goes the message';
END;
$BODY$
 LANGUAGE plpgsql;

Upvotes: 1

Views: 1979

Answers (1)

Vao Tsun
Vao Tsun

Reputation: 51511

try:

CREATE OR REPLACE FUNCTION myfunction()RETURNS TABLE(
cod INTEGER,
 answ CHARACTER VARYING
 ) AS $BODY$
 BEGIN
 RETURN QUERY
    select 0, 'here goes the message'::CHARACTER VARYING;
END;
$BODY$
 LANGUAGE plpgsql;

Upvotes: 1

Related Questions