-1

Note, I use tabs. Frequently, when I write answers on this site, I write them in vim with the assistance of vim-surround, especially when I'm migrating a fixed-width table/grid to a DDL. Here is an example of one such migration:

CREATE TABLE foo (man_id,subgroup,power,grp)
AS VALUES
    ( 1, 'sub_A', 'positive', 'Group_A' );

Now copy and paste the rendered code into psql and it'll work. But here is the catch. Edit this question (but don't mistakenly change anything), and copy the code block's raw markdown. This is part of a normal workflow, especially if there are knows bugs or typos and you want to fix them. Paste that raw Markdown into psql, and magically you get,

test=#     CREATE TABLE foo (man_id,subgroup,power,grp)
test-#     AS VALUES
test-#     ( ( 1, 'sub_A', 'positive', 'Group_A' );
test(# 

You'll see that the tab went away, and you have this blasted other parenthesis that you can't easily remove. Worse yet you almost have to guess the sequence of characters to get out of it from the prompt,

test(# )
test-# ;
ERROR:  syntax error at or near "test"
LINE 1: test=#     CREATE TABLE foo (man_id,subgroup,power,grp)

    ^

Is there anyway to tell psql to not do anything special here, or to act sanely under these circumstances (copy and paste)? Seems to be the result of the tab, which StackExchange muddles up into spaces on Markdown Rendering, making my life easier for copy-and-paste but more confusing to debug.

My version of psql is built with libedit,

libedit.so.2 => /usr/lib/x86_64-linux-gnu/libedit.so.2 (0x00007f294453f000)
4
  • "Not permitted" is a strong word (or two), but I do think that asking about the weird behaviour of copy/paste between vim in some kind of terminal, a web browser with unimaginable Markdown support, and psql is utterly off-topic. – mustaccio Jun 18 '18 at 23:43
  • It doesn't happen outside of the client why would the paste behavior inside the client be off-topic? This problem is a function of the client's tab-completion. This has nothing to do with VIM. I'm just stating that I personally use vim when converting grids to DDL. The problem has to do with copy-pasting raw markdown inside of PSQL and characters getting added. – Evan Carroll Jun 18 '18 at 23:44
  • This question is a "Tip of the iceberg" question and should be discussed with the vendor. You might have success with this question over on SuperUser. – John K. N. Jun 21 '18 at 7:08
  • @hot2use this isn't SQL Server. We don't require "vendors" we can customize our own software. =) – Evan Carroll Jun 21 '18 at 7:14
2

Debian doesn't actually use libedit, they just link against it to circumvent the GPL. What they do is PRELOAD libreadline which is a GPL and not a LGPL library. Ideally, libreadline would not tab-complete on newlines that had no non-whitespace characters, you can fix it to do just that.

Bracketed Paste

When I looked into patching this, libreadline already had that functionality,

enable-bracketed-paste When set to ‘On’, Readline will configure the terminal in a way that will enable it to insert each paste into the editing buffer as a single string of characters, instead of treating each character as if it had been read from the keyboard. This can prevent pasted characters from being interpreted as editing commands. The default is ‘off’.

All you need to do is add that to ~/.inputrc.

echo 'set enable-bracketed-paste on' >> ~/.inputrc

Now when you paste in the terminal, the terminal will send libreadline control chraceters which it will interpret to disable the tab-completion during paste. You can read more about this below,

This has also come up a already on the psql lists

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.