nerdexam
PostgreSQL_CE

PGCES-02 · Question #19

Select two appropriate statements from below about the following SQL statements: CREATE FUNCTION myfunc(INTEGER) RETURNS text LANGUAGE plpgsql STRICT AS ' DECLARE x ALIAS FOR $1; r text :=…

The correct answer is A. An error is generated unless theplpgsql language is registered in the database beforehand. E. When SELECTmyfunc (0) is executed the text "default" is returned. See the full explanation below for the reasoning.

Question

Select two appropriate statements from below about the following SQL statements:

CREATE FUNCTION myfunc(INTEGER) RETURNS text LANGUAGE plpgsql STRICT AS ' DECLARE x ALIAS FOR $1; r text := ''default''; BEGIN IF x > 100 THEN SELECT INTO r data FROM mytable WHERE id = x; END IF; RETURN r; END;';

Options

  • AAn error is generated unless theplpgsql language is registered in the database beforehand.
  • BThe execution results of SELECTmyfunc(-123) differs based on the content of "mytable".
  • CWhen SELECTmyfunc(123) is executed an error occurs.
  • DWhen SELECTmyfunc(NULL) is executed an error occurs.
  • EWhen SELECTmyfunc (0) is executed the text "default" is returned.

How the community answered

(38 responses)
  • A
    76% (29)
  • B
    8% (3)
  • C
    13% (5)
  • D
    3% (1)

Community Discussion

No community discussion yet for this question.

Full PGCES-02 Practice