Complete the code to create a simple utility function that returns the square of a number.
CREATE FUNCTION square(num integer) RETURNS integer AS $$ BEGIN RETURN num [1] num; END; $$ LANGUAGE plpgsql;The multiplication operator * is used to calculate the square of the number by multiplying it by itself.
Complete the code to call the utility function 'square' for the number 5.
SELECT [1](5);
power or sqrt instead of the custom function.The function square is the custom utility function we created to calculate the square of a number.
Fix the error in the function by completing the missing keyword to define the function body.
CREATE FUNCTION greet(name text) RETURNS text AS $$ [1] RETURN 'Hello, ' || name || '!'; END; $$ LANGUAGE plpgsql;
DECLARE instead of BEGIN to start the body.BEGIN keyword.The BEGIN keyword starts the function body in PL/pgSQL.
Fill both blanks to create a utility function that returns the length of a given text.
CREATE FUNCTION text_length(input_text text) RETURNS integer AS $$ [1] RETURN [2](input_text); END; $$ LANGUAGE plpgsql;
DECLARE instead of BEGIN to start the body.LEN which is not a PostgreSQL function.The function body starts with BEGIN and uses the built-in LENGTH function to get the text length.
Fill all three blanks to create a utility function that returns the uppercase version of a text input.
CREATE FUNCTION to_uppercase(text_input text) RETURNS text AS $$ [1] RETURN [2]([3]); END; $$ LANGUAGE plpgsql;
DECLARE instead of BEGIN.LOWER or misspelling UPPER.text_input.The function body starts with BEGIN, uses the UPPER function, and applies it to the input parameter text_input.