Q1
True / FalseA function in PostgreSQL can return a single value.
Functions in PostgreSQL can return a single value, which can be of any data type, such as integer, text, or boolean.
Q2
True / FalsePostgreSQL functions are created using the CREATE FUNCTION command.
The CREATE FUNCTION command is used to define a new function in PostgreSQL.
Q3
True / FalseFunctions in PostgreSQL cannot accept input parameters.
Functions in PostgreSQL can accept input parameters to perform operations based on the given input.
Q4
True / FalseIn PostgreSQL, functions can return a table as a result.
PostgreSQL functions can return a set of rows (a table) using the SETOF keyword or by specifying a composite type.
Q5
True / FalseFunctions in PostgreSQL can be written in multiple languages, such as SQL, PL/pgSQL, and PL/Python.
PostgreSQL supports functions written in various languages, including SQL, PL/pgSQL, PL/Python, PL/Perl, and more.
Q6
True / FalsePostgreSQL functions can include transaction control commands (COMMIT, ROLLBACK).
Functions in PostgreSQL cannot include transaction control commands like COMMIT or ROLLBACK. These commands are not allowed within the body of a function.
Q7
True / FalsePostgreSQL supports the creation of immutable functions that always produce the same result given the same input.
PostgreSQL allows the creation of immutable functions, which are functions that always return the same result for the same input and do not modify the database.
Q8
True / FalseYou can create a function in PostgreSQL that performs dynamic SQL execution using the EXECUTE statement.
PostgreSQL functions, particularly those written in PL/pgSQL, can perform dynamic SQL execution using the EXECUTE statement.
Q9
True / FalsePostgreSQL functions can use the ORACLE-specific DECODE function for conditional logic.
PostgreSQL does not support the ORACLE-specific DECODE function. Instead, it uses CASE expressions for conditional logic.
Q10
True / FalseWhen migrating functions from ORACLE to PostgreSQL, all PL/SQL functions can be directly transferred without any modification.
Migrating functions from ORACLE to PostgreSQL often requires modifications because PL/SQL (used in ORACLE) and PL/pgSQL (used in PostgreSQL) have different syntax and features. Functions need to be rewritten to ensure compatibility.
Q27
Multiple ChoiceCan functions in PostgreSQL return composite types?
SQL Code
CREATE TYPE product_details AS (
name VARCHAR,
price NUMERIC,
stock INT
);
CREATE OR REPLACE FUNCTION get_product_details(product_id INT)
RETURNS product_details AS $$
DECLARE
details product_details;
BEGIN
SELECT name, price, stock INTO details
FROM products
WHERE id = product_id;
RETURN details;
END;
$$ LANGUAGE plpgsql;
Yes, functions in PostgreSQL can return composite types, which allow for returning multiple related values as a single structured type.