I'm afraid I can't help with the first part of your problem, but you can solve the problem with your PL/PGSQL function by changing the type of the argument from text
to varchar
, so your definition becomes:
create or replace function test__upload(varchar) returns integer
as 'declare
p_filename alias for $1;
begin
copy mydb from p_filename USING DELIMITERS ''|'';
return 0;
end;' language 'plpgsql';
I'm not fully sure why this is solves the problem, but it does! text
is a bit of a PostgreSQL special type, which might have something to do with it. Any insight into this appreciated :). I shouldn't think that the character limit on a varchar
will bother you with a file name (I think the limit is 1024 chars in PostgreSQL, but it might be more).