Re: Escape char in pg_ls_dir

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Escape char in pg_ls_dir
Дата
Msg-id 19870.1514562317@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Escape char in pg_ls_dir  (lgcaracol <david.m.colaco@gmail.com>)
Список 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 по дате отправления:

Предыдущее
От: lgcaracol
Дата:
Сообщение: Escape char in pg_ls_dir
Следующее
От: Illya
Дата:
Сообщение: Tablespaces