The following bug has been logged on the website:
Bug reference: 16059
Logged by: Steven Winfield
Email address: steven.winfield@cantabcapital.com
PostgreSQL version: 11.5
Operating system: Linux
Description:
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.
[1] https://www.postgresql.org/docs/11/sql-copy.html
[2]
https://github.com/postgres/postgres/blob/4b011cad272e997935eb8d80ab741a40b395fdf5/src/bin/psql/tab-complete.c#L2234
[3]
https://github.com/postgres/postgres/blob/4b011cad272e997935eb8d80ab741a40b395fdf5/src/bin/psql/tab-complete.c#L4350