Products
Time series and Real-Time Analytics
Lightning-fast ingest and querying on PostgreSQL.
Time series and Real-Time AnalyticsDeployment options & services
Support Services
Support options for your use case, infrastructure, and budget.
Open-Source Extensions and Tools
Time Series and Real-Time Analytics
AI and Vector
Security Scanner
Industries That Rely On Us
Featured Articles
Scale PostgreSQL via Partitioning: A Dev’s Intro to Hypertables
Read more
Boosting Postgres INSERT Performance by 2x With UNNEST
Read more
Documentation
Learn PostgreSQL
Learn PostgreSQL
Learn the PostgreSQL basics and scale your database performance
Timescale Benchmarks
Timescale benchmarks
See how Timescale performs against the competition
$$
CREATE FUNCTION add(integer, integer) RETURNS integer
AS 'select $1 + $2;'
LANGUAGE SQL
IMMUTABLE
RETURNS NULL ON NULL INPUT;
$$
// Create a function to add 2 integers (SQL)
This function takes two integers as parameters
IMMUTABLE
means that the function cannot modify the database and always returns the same result when given the same argument values.
select add(5,9);
add
-----
14
(1 row)
// Function call (SQL)
\df
List of functions
Schema | Name | Result data type | Argument data types | Type
--------+------+------------------+---------------------+--------
public | add | integer | integer, integer | normal
(1 row)
// Display all Functions (psql)
\df+
// Display all functions and additional information, including owner, source code, and description, etc. (psql)
\ef myfunction
// Edit a function in default editor (psql)