O'Reilly logo

PostgreSQL Server Programming by Jim Mlodgenski, Kirk Roybal, Hannu Krosing

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding functionality to add(int, int)

While our function works, it adds nothing in the preceding code just using SELECT A + B, but functions written in C are capable of so much more. Let's start adding some more functionality to our function.

Smart handling of NULL arguments

Notice the use of STRICT keyword in the CREATE FUNCTION add(int a, int b) in the previously mentioned code. This means that the function will not be called if any of the arguments are NULL, but instead NULL is returned straight away. This is similar to how most PostgreSQL operators works, including the + sign when adding two integers—if any of the arguments are NULL the complete result is NULL as well.

Next, we will extend our function to be smarter about NULL inputs and act ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required