Consider a PostgreSQL function that returns the current user and the current timestamp. What will be the output of the following query?
SELECT current_user, now();
SELECT current_user, now();Think about what built-in PostgreSQL functions like current_user and now() do.
current_user returns the name of the current database user. now() returns the current date and time. Both are built-in functions that do not require parameters.
Which of the following best explains why server-side programming matters in database applications?
Think about where the data lives and how processing it near the data can help.
Server-side programming runs code on the database server, close to the data. This reduces the amount of data sent over the network and speeds up processing.
Identify the correct syntax for creating a simple PostgreSQL function that returns the current timestamp.
Remember the correct order and keywords for defining a function in PostgreSQL.
Option A correctly uses parentheses for parameters, specifies RETURNS, uses AS with dollar quoting, and ends with LANGUAGE plpgsql.
Which of the following best describes how server-side programming can optimize database query performance?
Consider where the heavy lifting happens in server-side programming.
Running logic inside the database server reduces the need to send large amounts of data over the network and allows the server to use indexes and optimizations effectively.
Given the following PostgreSQL function, what error will occur when calling it?
CREATE FUNCTION faulty_func() RETURNS integer AS $$ BEGIN RETURN 'text'; END; $$ LANGUAGE plpgsql;
SELECT faulty_func();Check the return type declared and the actual returned value type.
The function declares it returns an integer but tries to return a text string, causing a type mismatch error.