Re: Escape char in pg_ls_dir

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: lgcaracol <david(dot)m(dot)colaco(at)gmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Escape char in pg_ls_dir
Date: 2017-12-29 15:45:17
Message-ID: 19870.1514562317@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

lgcaracol <david(dot)m(dot)colaco(at)gmail(dot)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

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Illya 2018-01-04 19:49:01 Tablespaces
Previous Message lgcaracol 2017-12-29 10:00:56 Escape char in pg_ls_dir