On January 21th at 14:15 UTC , progression through exercises will be unavailable for 10 minutes due to a planned maintenance break.
Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
8. Summary


Great! Now that you've got a basic grasp on functions, let's briefly review what have we learned in this part:

  • User-defined functions extend the functionality of a database.
  • The primary advantages of using user-defined functions are code re-usability and custom logic.
  • We use the CREATE FUNCTION statement to create a new function:
    CREATE FUNCTION get_circumference(diameter decimal)
    RETURNS decimal AS $$
      RETURN get_pi() * diameter;
  • Warning: each database engine (Oracle, SQL Server, etc.) has slightly different syntax for creating functions, though the concepts are similar in all database engines.
  • PL/pgSQL is the most common language for writing a function in PostgreSQL. You can use other languages (like Perl, Python, etc.), but they are less frequently used.


Click Next exercise to continue.