liveBook · Manning

Database function

As explained in Learn SQL in a Month of Lunches

A database function is a named database routine or SQL operation that computes and returns a value, optionally from supplied arguments.

A database function is a named SQL operation that performs a predefined calculation or other action. Like a spreadsheet’s SUM formula, it can calculate, extract, combine, convert, or format values. section 12.0 section 12.1

Call a function by writing its name followed by parentheses containing a column, variable, or other value. Functions can appear in queries that select or filter data. section 14.0 section 14.2.1

Uppercase customer names

To display California customers with both their stored names and uppercase versions, apply UPPER to each name column and assign readable aliases. section 14.2.1

SELECT
    FirstName,
    LastName,
    UPPER(FirstName),
    UPPER(LastName)
FROM customer
WHERE State = 'CA';

This query demonstrates applying a function to selected columns while filtering rows with a WHERE condition. section 14.2.1

Common jobs for database functions include:

  • Calculate totals, minimums, maximums, and averages across a range of values. section 12.1
  • Extract parts of dates and times, such as the year, month, day, hour, minute, or second. section 14.3
  • Change strings and values, including converting text to uppercase or lowercase and converting values into new forms. section 15.2 section 14.2.1

Use functions thoughtfully on large data sets: they may read every value in a range and consume additional server resources. Function names and syntax also vary among relational database systems. section 14.1.1 section 14.1.2

How Learn SQL in a Month of Lunches covers it

How deep it goes
Explains function purpose, argument syntax, practical categories, efficiency cautions, and RDBMS variation without covering implementation internals.
Examples
Demonstrates spreadsheet totals, aggregate calculations, and UPPER or LOWER applied to California customer names.
What it assumes
Assumes familiarity with basic SELECT, FROM, WHERE, and GROUP BY clauses while teaching function use through spreadsheet comparisons.
What you can do after
Apply it via SQL to calculate, extract, filter, combine, convert, or format values while recognizing portability and efficiency issues.
How it connects
Connects database functions with aggregate functions, string functions, date and time functions, informational functions, and filtering.

Also explained in

Compare how 3 books explain database function →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn SQL in a Month of Lunches. The section links point to the parts of the book it draws on.