Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Summary
8. Summary

Instruction

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 $$
    BEGIN
      RETURN get_pi() * diameter;
    END;
    $$ LANGUAGE PLpgSQL;
    
  • 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.

Exercise

Click Next exercise to continue.