SQL Tutorial

SQL Functions

Functions

Functions group reusable logic behind a name you can call anywhere.

CREATE FUNCTION course_count() RETURNS INTEGER AS $$
  SELECT COUNT(*) FROM courses;
$$ LANGUAGE sql;
Try it Yourself
Run this SQL example in your local environment or course sandbox.