pgcli icon indicating copy to clipboard operation
pgcli copied to clipboard

Implement \copy (...) TO PROGRAM '...'

Open thalesmello opened this issue 8 years ago • 6 comments

Hello.

Excellent project! So far, pgcli replaced the old psql except for this one feature.

psql allows you to use the \copy command to pipe a query into a shell command, which might be useful to copy the results of a query to the system clipboard (using pbcopy on a Mac, though there are similar utilities for GNU/Linux and Windows). Therefore, if I do something like:

\copy (SELECT name, age FROM Users) TO PROGRAM 'pbcopy' DELIMITER e'\t' CSV HEADER

It copies the result of the query to the clipboard and then I can easily paste it into a spreadsheet application.

I would like to be able to do something like this on pgcli as well.

How difficult would it be to implement this?

thalesmello avatar Jul 29 '16 18:07 thalesmello

In psql we can also do \g | pbcopy which would basically copy the results from last query to clipboard. I really miss this in pgcli.

assembler avatar Oct 11 '18 11:10 assembler

Any updates? wonder how people export query result to clipboard or external editors like vscode

yilinjuang avatar Apr 20 '21 05:04 yilinjuang

Clipboard should be an optional solution because you could use this tool to export large volume of data which should not be stored in clipboard.

Export to disk like currently with \o filename except in structured format e.g. CSV, JSONL etc. would amazing to have!

lordlycastle avatar Jun 08 '21 11:06 lordlycastle

+1 to this, some kind of "copy last results" feature would be great. the point about large data size is reasonable but IMO this is a developer tool and you should give ppl the flexibility to choose that when it's appropriate.

This is especially frustrating due to pgcli's default behavior of truncating the later columns of wide table outputs. That's a nice feature for when you're browsing interactively, but makes it hard to retrieve that info to clipboard, since the later columns get truncated.

worace avatar May 30 '23 20:05 worace

+1 copy results to clipboard select id from table

radoslawklak avatar Oct 18 '23 07:10 radoslawklak

any chance on this ?

rklak avatar Mar 11 '24 23:03 rklak