Prepstellar

SQL Fundamentals · Practice set 7 of 7

Values, Types, and Expressions: 10 practice questions

10 questions · Untimed · Free

10 free SQL Fundamentals practice questions on Values, Types, and Expressions, with an explanation for every answer. Untimed. The full mock exam and the timed version are in the app.

Set 7 · Values, Types, and Expressions · 10 questions Read the lesson
  1. Question 1 of 10

    A short value is stored into a fixed-length character column. How is it held?

    1. AShifted into the text type to avoid the padding
    2. BPadded with spaces out to the declared width
    3. CRejected, because the declared width was not filled
    4. DStored exactly as written, without any padding
    Show the answer

    The blank-padded character type widens a short value with spaces and stores and displays it that way, and it then ignores those trailing spaces when two such values are compared; character varying is the type that keeps a short value as written.

    Next → 1 / 10
  2. Question 2 of 10

    Which PostgreSQL type is documented for holding logical true or false values?

    1. Abytea
    2. Bbit varying
    3. Cboolean
    4. Dbit
    Show the answer

    The boolean type, with its alias bool, is the documented logical type for truth values and is named by the SQL standard; the bit types hold strings of bits and bytea holds binary data, so none of them expresses a truth value.

    Next → 2 / 10
  3. Question 3 of 10

    How does the BETWEEN predicate treat the two endpoint values of its range?

    1. AThe upper endpoint alone is included
    2. BBoth endpoints are excluded from the range
    3. CThe lower endpoint alone is included
    4. DBoth endpoints are included in the range
    Show the answer

    BETWEEN is defined as the combination of a greater-than-or-equal test against the lower value and a less-than-or-equal test against the upper one, so a value equal to either endpoint passes; an exclusive range has to be written out with strict comparisons.

    Next → 3 / 10
  4. Question 4 of 10

    A numeric value is written with two digits before the decimal point and four after it. What are its precision and its scale?

    1. AA precision of six and a scale of four
    2. BA precision of four and a scale of six
    3. CA precision of two and a scale of four
    4. DA precision of four and a scale of two
    Show the answer

    Precision counts the significant digits on both sides of the decimal point while scale counts only the fractional digits, so the two figures are never the same count and precision is the wider of the pair here.

    Next → 4 / 10
  5. Question 5 of 10

    An arithmetic expression mixes an addition and a multiplication with no parentheses. How is it grouped, and how can that be changed?

    1. AThe operators are applied strictly from left to right as written
    2. BAddition binds first, and a cast is the way to regroup it
    3. CMultiplication binds first, and parentheses are the way to regroup it
    4. DGrouping depends on the planner, and a hint is the way to regroup it
    Show the answer

    Precedence is hard-wired in the parser, with multiplication, division, and modulo binding more tightly than addition and subtraction, so only parentheses can impose a different reading; note that precedence settles grouping, not the order in which subexpressions are actually evaluated.

    Next → 5 / 10
  6. Keep the ones you got wrong

    In the app, every question you miss comes back exactly when you’re about to forget it.

  7. Question 6 of 10

    Which ordering describes how the logical operators bind, from the tightest to the loosest?

    1. ANOT, then AND, then OR
    2. BOR, then AND, then NOT
    3. CAND, then OR, then NOT
    4. DNOT, then OR, then AND
    Show the answer

    The documented precedence places logical negation above conjunction and conjunction above disjunction, so an unparenthesised mixture groups the negations first and the disjunction last; parentheses are what override that reading.

    Next → 6 / 10
  8. Question 7 of 10

    A function declares three parameters where the second and third carry defaults. Which call form can supply a value for the third parameter while leaving the second at its default?

    1. APositional notation, which fills a gap with an empty argument slot
    2. BPositional notation, which can omit a parameter at any position
    3. CNamed notation, provided the named arguments are written before the positional ones
    4. DNamed notation, which can omit any combination of defaulted parameters
    Show the answer

    Named notation matches arguments to parameters by name and can therefore skip any defaulted parameter, while positional notation can only drop defaulted parameters from the right, and mixed notation still requires the positional arguments to come first.

    Next → 7 / 10
  9. Question 8 of 10

    A ledger column stores monetary amounts that must be summed without accumulated rounding drift, and equality tests on stored balances must behave predictably. Reporting speed is a secondary concern. Which type fits?

    1. Anumeric, with a declared precision and scale
    2. Bbigint, storing the amount as whole units
    3. Cdouble precision, for its wider documented range
    4. Dreal, for its smaller per-value storage cost
    Show the answer

    Exactness is the deciding requirement, and numeric is the type the documentation recommends for monetary amounts, accepting that its calculations are slower; the floating-point types are documented as inexact, which is why equality tests on them can behave unexpectedly.

    Next → 8 / 10
  10. Question 9 of 10

    A label must join a literal text prefix to a numeric column using the concatenation operator, and the code must not depend on the engine accepting a non-string operand. Which approach is dependable?

    1. ACoerce the literal prefix to the numeric column's type first
    2. BCoerce the numeric column to text explicitly before joining it
    3. CJoin the operands directly, since one operand is already text
    4. DWrap both operands in an array and join the arrays
    Show the answer

    The operator accepts a non-string operand only because one side is already a string, so writing the conversion by hand keeps the expression from relying on that accommodation; converting the string side to a number instead removes the string operand the operator needs.

    Next → 9 / 10
  11. Question 10 of 10

    An audit column must record a calendar date and a clock time in a single value, and the zone in which the moment was recorded must be part of the stored value. Which type declaration satisfies both requirements?

    1. Atimestamp with time zone
    2. Bdate
    3. Ctime with time zone
    4. Dtimestamp without time zone
    Show the answer

    Only the with-time-zone spelling of the combined date-and-time type carries zone information alongside the moment, and only a timestamp carries both halves of that moment; a time-only or date-only type drops one of the two required components.

    Next → 10 / 10
  12. You’ve finished this set

    That’s 10 questions on Values, Types, and Expressions. In the app the ones you miss come back exactly when you’re about to forget them.

The whole course, on your phone

Lessons you can read, audio you can listen to on the way to work, and practice that remembers what you got wrong.