PostgreSQL Types by Reference
When writing a function to work with a specific table structure, you may have to match the argument types with table columns. If a table column changes its name, you may or may not need to rework the function to apply a similar change. If the table column changes its type, you almost certainly need to change the function to follow the update.
Today I encountered that problem and discovered the option of assigning types by reference. The CREATE FUNCTION
documentation says this:
The type of a column is referenced by writing
table_name.column_name%TYPE
. Using this feature can sometimes help make a function independent of changes to the definition of a table.
Per the docs, this applies to function arguments and function return values. It also applies to function variables. Maybe it applies elsewhere also, but this alone is a considerable benefit!