Database function
A database function is a named routine stored or executed in a database that accepts inputs and computes a result, often a scalar or table-valued result.
Just Use Postgres!
A database function is a stored routine that accepts inputs, performs computation or data operations, and returns a value or result within the database.
- How it is used
- Deploys reusable data-coupled business logic and multistep operations for applications, microservices, and database-backed APIs.
- How deep it goes
- Defines SQL functions and demonstrates parameters, return tables, conditionals, updates, exceptions, and replacement, without deep administration guidance.
- Examples
- Uses product-price lookup, pending shopping carts, item addition, checkout totals, and database-backed message APIs as examples.
- What you can do after
- Build it from scratch using CREATE OR REPLACE FUNCTION, call it from SQL, inspect returned rows, and centralize multistep data workflows.
PostgreSQL Mistakes and How to Avoid Them
A database function is a named routine stored in the database that accepts inputs and produces a result or side effect.
- How it is used
- Uses stored routines to return values or perform database-side actions while emphasizing ownership and execution privileges.
- How deep it goes
- Explains execution privileges through a destructive scenario but stops short of function syntax or internal implementation.
- Examples
- Uses reset_schema(), count(), and data type conversion functions as examples of side effects, NULL handling, and migration compatibility.
- What you can do after
- Operate database functions more safely by reviewing ownership, execution rights, side effects, NULL behavior, and migration compatibility.
Read how PostgreSQL Mistakes and How to Avoid Them explains database function →
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.
- How it is used
- Uses SQL functions to calculate, select, filter, transform, and inspect database values.
- 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 you can do after
- Apply it via SQL to calculate, extract, filter, combine, convert, or format values while recognizing portability and efficiency issues.
Read how Learn SQL in a Month of Lunches explains database function →
Related concepts
- SYSTEM$CLUSTERING_INFORMATIONincludes · SYSTEM$CLUSTERING_INFORMATION is a Snowflake system function that returns statistics describing how well a table is clustered for specified columns.
- coalesce functionincludes · The COALESCE function returns the first non-null value among its arguments, or null if all arguments are null.
- nowincludes · A now operation or keyword yields or derives a value representing the current date or time according to a relevant clock or system.
- timestampincludes · A timestamp is a value representing a specific point in time, typically associated with an event, observation, or data item.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.


