From the course: Advanced SQL for Data Scientists

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Function overloading

Function overloading

From the course: Advanced SQL for Data Scientists

Start my 1-month free trial

Function overloading

- [Instructor] Postgres supports the concept of function overloading. Now basically what this means is that a single function can actually have multiple definitions. Now, the way we do this is we use multiple create function statements, but those create function statements have different signatures or a different set of parameters. So for example, we could create a harmonic mean like the one we have created earlier, which takes in two arguments, both of which are numeric. We could also create a harmonic mean that takes in text values and then converts them. Function overloading is useful when the same function can apply or be applied to different data types. Now, one thing you want to keep in mind is you want to avoid anything that might be ambiguous in terms of how Postgres will interpret the particular signatures. So for example, if we called a function, let's call it ambiguous, and we passed in the value eight, well…

Contents