All the following uses of pg_read_file() are running fine:
select pg_read_file('myFile.txt'); -- ok full file
select pg_read_file('myFile-notExists',0,10,true); -- NULL is Ok!
But these are problematic:
select pg_read_file('myFile-notExists.txt'); -- ERROR... It is not what I need
select pg_read_file('myFile.txt',0,10,true); -- ok not null, but need full file!
... I try to solve the problem with a wrap function:
CREATE or replace FUNCTION pg_read_file(f text, missing_ok boolean) RETURNS text AS $$
SELECT pg_read_file(f,0,922337203,missing_ok)
-- the max 9223372036854775807 is too large, also 9223372036854775800, ....
$$ LANGUAGE SQL IMMUTABLE;
But it say "ERROR: requested length too large" for tests on maximum length... So I using aleatory constant. Question1: what the "max file size" value?
select pg_read_file('myFile-notExists.txt',true); -- Ok! NULL is what I need
select pg_read_file('myFile.txt',true); -- Ok! full file.
Question2: is there another way to solve this problem?
At standard PostgreSQL v12 \df pg_read_file
says:
Schema | Name | Result data type | Argument data types | Type
------------+--------------+------------------+-------------------------------+------
pg_catalog | pg_read_file | text | text | func
pg_catalog | pg_read_file | text | text, bigint, bigint | func
pg_catalog | pg_read_file | text | text, bigint, bigint, boolean | func
Why pg_read_file(text,boolean)
is not in the pg_catalog? It will produce some inconsistence with other modules or extensions?