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: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
Cc: pgsql-hackers@lists.postgresql.org, steven.winfield@cantabcapital.com
Date: 2020-01-06T06:06:28Z
Lists: pgsql-bugs, pgsql-hackers
Attachments
- psql-filename-completion-fixes-5.patch (text/x-diff) patch
I wrote: > Peter Eisentraut <peter.eisentraut@2ndquadrant.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, say, \lo_import myf<TAB> to \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 [1] https://www.postgresql.org/message-id/13708.1578059577%40sss.pgh.pa.us
Commits
-
Improve psql's tab completion for filenames.
- cd69ec66c886 13.0 landed
-
Modernize our readline API a tad.
- 5e7bedc5adba 13.0 landed
-
Add tab completion for EXPLAIN (SETTINGS) in psql
- 4b011cad272e 13.0 cited