Edit the Return of a function using postgresql

Asked

Viewed 20 times

0

Hello!

I have the following function (using pgadmin and postgresql), and I would like to edit the Return so that in "data output" instead of just "The sum of the numbers is: 10", the " would be shown The value of numero1 + numero2 is 10!"

CREATE OR REPLACE FUNCTION soma(numero1 int, numero2 int) RETURNS text AS $$ BEGIN RETURN 'The sum is: ' || numero1 + numero2; END; $$ LANGUAGE plpgsql;

SELECT soma(25,2);

Data Output - The sum is: 10

But I would like it to be shown: The sum of 25 + 2 is: 27!

1 answer

0

Try:

CREATE OR REPLACE FUNCTION soma(numero1 int, numero2 int) RETURNS text AS $$ 
BEGIN 
RETURN 'A soma é: ' concat(numero1, ' + ', numero2, ' = ', numero1 + numero2); 
END; 
$$ LANGUAGE plpgsql;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.