One thing which went unexplained in the previous sample was the error reporting part:
if (ARR_NDIM(input_array) > 1) ereport(ERROR, (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR), errmsg("use only one-dimensional arrays!")));
All error reporting and other off-channel messaging in PostgreSQL is done using the
ereport(<errorlevel>, rest) macro. The main purpose of which is to make error reporting look like a function call.
The only parameter which is processed directly by
ereport() is the first argument error level, or perhaps more exactly severity level or log level. All the other parameters are actually function calls which independently generate and store additional error information in the system to be written to logs ...