Re: BUG #16059: Tab-completion of filenames in COPY commands removes required quotes

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: steven.winfield@cantabcapital.com
Cc: pgsql-bugs@lists.postgresql.org
Date: 2019-11-02T21:14:20Z
Lists: pgsql-bugs, pgsql-hackers

Attachments

PG Bug reporting form <noreply@postgresql.org> writes:
> As per the documentation[1], the COPY command requires the output filename
> to be single-quoted.

> However, when using psql, a partial COPY command such as this...
> COPY pg_catalog.pg_class TO '/usr
> ...will, on hitting TAB, be converted to this...
> COPY pg_catalog.pg_class TO /usr/
> ...requiring the user to move the cursor back to re-insert the single quote
> before finishing the command and executing.

> The issue seems to be somewhere around here[2], where complete_from_files[3]
> is used to suggest replacements - that function strips quotes from the
> existing (partial) filename but doesn't put them back unless quote_if_needed
> is true (which I guess it isn't, unless there is a space in the filename for
> example).

> Note that using the \copy command instead works fine, as filenames do not
> need to be quoted in that case.

Yeah, it seems like a bad idea to override the user's choice to write
a quote, even if one is not formally necessary.  I propose the attached.

			regards, tom lane

Commits

  1. Improve psql's tab completion for filenames.

  2. Modernize our readline API a tad.

  3. Add tab completion for EXPLAIN (SETTINGS) in psql