Immutability

What happens when a function is called over and over again with the same arguments? It is executed over and over again, which is quite easy to understand. PostgreSQL allows a function to declare a level of immutability so that the query executor can make some assumptions to improve the speed of the execution.

To better understand this concept, consider the f_human_file_size() function shown in Listing 46The function accepts a numeric argument and produces a text representation of that argument:

testdb=> SELECT f_human_file_size( 1234567890 ); f_human_file_size------------------- 1.15MB

Reading the function implementation, it is clear that such a function will provide the same result for the same input every time and it would ...

Get PostgreSQL 11 Server Side Programming Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.