Re: Escape char in pg_ls_dir - Mailing list pgsql-novice

From Tom Lane
Subject Re: Escape char in pg_ls_dir
Date
Msg-id 19870.1514562317@sss.pgh.pa.us
Whole thread Raw
In response to Escape char in pg_ls_dir  (lgcaracol <david.m.colaco@gmail.com>)
List pgsql-novice
lgcaracol <david.m.colaco@gmail.com> writes:
> I'm new to postgresql. I have a database running on a windows machine and I
> need to use pg_ls_dir to list the contents of a folder, but I can't because
> of the backslash (\), as it's not allowed.
> If I run select pg_ls_dir('c:') I can see the listing of C:\, but I need to
> check another folder.
> If I run select pg_ls_dir(E'c:\inetpub'), I got an error "could not open
> directory "c:inetpub": No such file or directory. So I now the \ is not
> being used.
> If I run select pg_ls_dir('c:\\inetpub'), it says "absolute path not
> allowed".

That's intentional: the documentation for pg_ls_dir and friends says in
so many words "Only files within the database cluster directory and the
log_directory can be accessed".  (It seems like a Windows-specific bug
to me that we allow a drive prefix.)

If you want access to random bits of the server's filesystem, I'd suggest
installing plperlu or plpythonu and writing up your own access functions.
"List this directory" should be just a couple of lines in either language.

BTW, your confusion about how to write a backslash in a string literal
would perhaps be dispelled here:

https://www.postgresql.org/docs/current/static/sql-syntax-lexical.html#SQL-SYNTAX-CONSTANTS

Neither of the ways you used above is quite right; you should either
write E'c:\\inetpub' or just 'c:\inetpub'.

            regards, tom lane


pgsql-novice by date:

Previous
From: lgcaracol
Date:
Subject: Escape char in pg_ls_dir
Next
From: Illya
Date:
Subject: Tablespaces