If I want to read a file that I'm not sure of the existence but I want to read the whole file if exists, I would call pg_read_binary_file('path', 0, -1, true) but unfortunately this doesn't work.
Does it make sense to change the function so as to accept the parameter specification above? Or the arguments could be ('path', null, null, true) but (0,-1) is simpler considering the characteristics of the function. (We could also rearrange the the parameter order as "filename, missing_ok, offset, length" but that is simply confusing..) If it is, pg_read_file() is worth receive the same modification and I'll post the version containing doc part. regards. -- Kyotaro Horiguchi NTT Open Source Software Center
diff --git a/src/backend/utils/adt/genfile.c b/src/backend/utils/adt/genfile.c index 2bf5219256..219203be1c 100644 --- a/src/backend/utils/adt/genfile.c +++ b/src/backend/utils/adt/genfile.c @@ -331,10 +331,10 @@ pg_read_binary_file(PG_FUNCTION_ARGS) seek_offset = PG_GETARG_INT64(1); bytes_to_read = PG_GETARG_INT64(2); - if (bytes_to_read < 0) + if (bytes_to_read < -1) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("requested length cannot be negative"))); + errmsg("invalid requested length"))); } if (PG_NARGS() >= 4) missing_ok = PG_GETARG_BOOL(3);