2

When entering long queries into the command-line psql, my terminal[1] is not wrapping the input line correctly. Additional charactes wrap back to the left of the screen, but on the same line as the existing text, and further editing is difficult. How can I enable multi-line editing in psql?

Mutli-line editing in bash via SSH wraps correcty, so this is related to psql specifically.

For reference:

$ psql --version
psql (PostgreSQL) 8.4.21
contains support for command-line editing

This is unrelated to using screen/byobu? When I launch psql outside of screen/byobu. it displays multi-line inputs somewhat better (they now span multiple lines), but editing is still not possible due to incorrect positioning of the cursor.

I experienced similar difficulties editing long input lines when using iTerm2 with and without screen/byobu.

In both cases, the terminals were set to default value for emulation (xterm-256color).

I experienced the same difficulties using xfce4-terminal in Xubuntu in a VirtualBox.

I experienced the same difficulties using PuTTY from a Microsoft Windows Vista computer.

Has psql ever handled multi-line editing correclty? I've used it for years and have never experienced this difficuty before ...

[1] Terminal.app in Apple Mac OS X Mavericks, with a secure shell session to an Ubuntu server running bash.

6
  • 1
    psql uses libedit (a BSD thing, ironic that it wouldn't work on OS/X), not readline (a GNU thing). Aug 6, 2014 at 9:59
  • This seems variable, as this page states that psql can be compiled with readline: postgresql.org/docs/8.4/static/app-psql.html
    – SabreWolfy
    Aug 6, 2014 at 10:03
  • OK, I stand corrected, so what is it for you (I suppose if bash works, it's probably not readline)? ldd /usr/lib/postgresql/*/bin/psql | grep -e libedit -e readline Aug 6, 2014 at 10:05
  • libedit.so.2 => /usr/lib/i386-linux-gnu/libedit.so.2 (0xb75f2000) libedit.so.2 => /usr/lib/i386-linux-gnu/libedit.so.2 (0xb76f9000)
    – SabreWolfy
    Aug 6, 2014 at 10:06
  • It might help to compare the output of infocmp on OS/X and Ubuntu. What's $TERM? Does it work better with TERM=Apple_Terminal? Aug 6, 2014 at 10:06

1 Answer 1

1

This was related to the psql prompt, as set in the .psqlrc file. Renaming this file and restarting psql solved the problem.

3
  • I have used this prompt for a number of years, without any difficulties editing command line input. Possibly an update to psql and/or libedit resulted in this.
    – SabreWolfy
    Aug 6, 2014 at 15:00
  • What was that prompt? Maybe that can be reported as a bug to postgresql/libedit. Aug 6, 2014 at 15:11
  • \set PROMPT1 '%[%033[1;33m%]%/%[%033[32m%]%R%#%[%33[0m%] ' \set PROMPT2 '%[%033[1;33m%]%/%[%033[31m%]%R%#%[%33[0m%] '
    – SabreWolfy
    Aug 6, 2014 at 15:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .