SQLite Forum

Custom error messages for required table-valued function parameter
> The SQLITE_CONSTRAINT return is useful for table-valued functions that have
> required parameters. If the aConstraint[].usable field is false for one of the
> required parameter, then the xBestIndex method should return SQLITE_CONSTRAINT.

You should return SQLITE_CONSTRAINT if the required parameter is present in the aConstraint[] array but with usable=0. No need for an error message in this case - some other invocation of xBestIndex will have usable=1 for the required parameter and the vtable will be able to proceed. If the required parameter is not present in aConstraint[] at all, return SQLITE_ERROR and an error message.