Skip site navigation (1) Skip section navigation (2)

Re: psql filename completion: quoting

From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Noah Misch <noah(at)leadboat(dot)com>
Cc: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: psql filename completion: quoting
Date: 2012-02-28 04:20:31
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-hackers
Excerpts from Noah Misch's message of sáb ene 14 12:20:18 -0300 2012:
> Occasionally, I have a SQL file destined for psql's \i command whose name
> contains a space.  Less often, I'll have a .csv destined for \copy with the
> same problem.  psql's filename completion does not handle these well.  It
> completes on the literal name, but the commands will only recognize quoted
> names.  For example, given a file "foo bar", "\i f<TAB>" will complete to "\i
> foo bar", which will not execute.  If I type "\i 'f<TAB>", completion will not
> help at all.
> The attached patch wraps rl_filename_completion_function() to dequote on input
> and enquote on output.  Now, "\i f<TAB>" and "\i 'f<TAB>" will both complete
> to "\i 'foo bar'", which executes as expected.  The new code handles embedded
> whitespace, quotes, and backslashes.

Nice -- thanks, pushed.

> tab-complete.c works in terms of whitespace-separated words.  As such, "\i
> 'foo b<TAB>" does not complete, because tab-complete.c has no notion of quotes
> affecting token boundaries.  It thinks "'foo" is one token and "b" is another.

Yeah, it's a bit annoying if you have both "a b" and "a c".  If you have
a file named a\b, attempting to complete past a\\ doesn't work either.
(If you have 'a\\ it does work, however).

Álvaro Herrera <alvherre(at)commandprompt(dot)com>
The PostgreSQL Company - Command Prompt, Inc.
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

In response to

pgsql-hackers by date

Next:From: Pavel StehuleDate: 2012-02-28 04:59:28
Subject: Re: Trigger execution role (was: Triggers with DO functionality)
Previous:From: Rob WultschDate: 2012-02-28 03:52:39
Subject: Re: swapcache-style cache?

Privacy Policy | About PostgreSQL
Copyright © 1996-2018 The PostgreSQL Global Development Group