Leveling Up With Built-In SQL Functions: A Comprehensive Beginner's Guide
Going Beyond the PostgreSQL Basics With Built-In Functions
Every SQL database supports various built-in functions to help you transform data and perform mathematical calculations. Built-in functions are specific to SQL databases. However, across databases, built-in functions often differ in name but are equivalent in behavior.
Broadly speaking, there are three main categories of functions. (As always, the examples in my articles are for PostgreSQL.)
Mathematical Operations: These functions perform arithmetic calculations on numeric data. Examples include ABS()
, CEIL()
, ROUND()
, and SQRT()
.
String Operations: These functions manipulate or pull information from string data. Examples include LOWER()
, UPPER()
, CONCAT()
, SUBSTRING()
, LEFT()
, RIGHT()
and LENGTH()
.
Date Operations: These functions work with date and time values. Examples include EXTRACT()
, TO_DATE()
, CURRENT_DATE()
, and TO_CHAR()
.
Built-in functions take in zero or more arguments passed to the function within its parentheses. These arguments are either values the function will use in its operation or additional configuration options.