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 FUNCTIONstatement 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 to continue.



