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

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org, steven(dot)winfield(at)cantabcapital(dot)com
Subject: Re: BUG #16059: Tab-completion of filenames in COPY commands removes required quotes
Date: 2020-01-06 06:06:28
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

I wrote:
> Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com> writes:
>> I haven't found an explanation in this thread why it does always quote
>> now. That seems a bit unusual. Is there a reason for this? Can we do
>> without it?

> The core problem we're trying to solve is stated in the thread title:
> ...
> It'd be possible, perhaps, to distinguish between this case and the
> cases in backslash commands, which are okay with omitted quotes
> (for some filenames). I'm not sure that that would be an improvement
> though.

I realized that there *is* a good reason to worry about this. Fairly
recent versions of libedit will try to backslash-escape the output
of psql_completion(), as I described over at [1]. This is absolutely
disastrous if we've emitted a quoted filename: we end up going from,
\lo_import myf<TAB>
\lo_import \'myfile\'
which of course doesn't work at all (psql thinks \' is in itself a
backslash command).

There isn't much we can do about this in contexts where we must
quote the filename: not doing so produces an equally broken command.
However, this problem does suggest that we shouldn't force quoting
if we don't have to, as that just breaks cases we needn't break.

Hence, the attached revision only forces quoting in a SQL COPY
command, or if the user already typed a quote.

I also added some regression tests (whee!). They pass for me with a
couple different readline and libedit versions, but I have only minimal
hopes for them passing everywhere without further hacking ... the
results of the other thread suggest that pain is to be expected here.

regards, tom lane


Attachment Content-Type Size
psql-filename-completion-fixes-5.patch text/x-diff 24.7 KB

In response to


Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2020-01-06 06:21:35 Re: BUG #16190: The usage of NULL pointer in refint.c
Previous Message Fahar Abbas 2020-01-06 05:49:38 Re: postgresql mac operation issue 10.11

Browse pgsql-hackers by date

  From Date Subject
Next Message Arthur Zakirov 2020-01-06 06:20:13 Re: Add pg_file_sync() to adminpack
Previous Message Michael Paquier 2020-01-06 06:01:52 Re: Setting min/max TLS protocol in clientside libpq