Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
2. Example: get_pi() function
Summary

Instruction

Let's first start with an example. Our first function simply returns the constant approximate value of pi: 3.14159265358979.

Postgres has a built-in pi() function that returns this value, but for our purposes, we will not be using it – so forget it for now 😉

Exercise

Carefully review the source code of the get_pi() function. Observe that the code consists of the:

  • CREATE FUNCTION command.
  • Function name, get_pi().
  • Return type (decimal).
  • Function body.
  • Language option (in this case PLpgSQL).

All parts of the code listed above will be explained in the next exercises.

Go ahead and execute the code, which will create the get_pi() function.