-
Notifications
You must be signed in to change notification settings - Fork 549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for \clip command #1264
base: main
Are you sure you want to change the base?
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1264 /- ##
==========================================
- Coverage 83.82% 83.48% -0.34%
==========================================
Files 21 21
Lines 2559 2604 45
==========================================
Hits 2145 2174 29
- Misses 414 430 16
Continue to review full report at Codecov.
|
This does belong in pgspecial package. We do have custom commands that are not DB commands in pgspecial. Take a look at the iocommands file in pgspecial. Also have a look at the develop.rst file, it talks a bit about how to add special commands. |
Here's a reference implementation from mycli: https://github.com/dbcli/mycli/blob/master/mycli/packages/special/iocommands.py#L165 |
psql has command \g | postgres=# explain select * from o obce obce_id_seq okresy postgres=# explain select * from obce limit 10 \g | wl-copy postgres=# There are lot of use cases - copy to clipboard is just one. |
@okbob, thanks for informing me about this. It is definitely very useful. But for my case it isn't enough. This is because I typically need the raw JSON format for pev2, and the output of
to the clipboard. So unless there is some some |
út 18. 5. 2021 v 10:07 odesílatel Paweł Sacawa ***@***.***>
napsal:
@okbob <https://github.com/okbob>, thanks for informing me about this. It
is definitely very useful. But for my case it isn't enough. This is because
I typically need the JSON format for pev2 <https://explain.dalibo.com/>,
and the output of EXPLAIN (ANALYZE, format json) SELECT * from mytable \g
| xsel -ib gives me:
QUERY PLAN
-------------------------------------
[
{
"Plan": {
"Node Type": "Seq Scan",
"Parallel Aware": false,
"Relation Name": "mytable",
"Alias": "mytable",
"Startup Cost": 0.00,
"Total Cost": 35.50,
"Plan Rows": 2550,
"Plan Width": 4,
"Actual Startup Time": 0.005,
"Actual Total Time": 0.005,
"Actual Rows": 0,
"Actual Loops": 1
},
"Planning Time": 0.094,
"Triggers": [
],
"Execution Time": 0.029
}
]
(1 row)
So unless there is some some \pset option I don't know, then a more
fine-grained is required.
It is solved in psql 13, where you can use one shot parameters for \g
explain (format json) select * from pg_class limit 10 \g (format=unaligned
tuples_only) | wl-copy
[
{
"Plan": {
"Node Type": "Limit",
"Parallel Aware": false,
"Async Capable": false,
"Startup Cost": 0.00,
"Total Cost": 0.43,
"Plan Rows": 10,
"Plan Width": 265,
"Plans": [
{
"Node Type": "Seq Scan",
"Parent Relationship": "Outer",
"Parallel Aware": false,
"Async Capable": false,
"Relation Name": "pg_class",
"Alias": "pg_class",
"Startup Cost": 0.00,
"Total Cost": 16.96,
"Plan Rows": 396,
"Plan Width": 265
}
]
}
}
]
… —
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1264 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAEFO47KNXDKNLTRRCNK2DDTOIN25ANCNFSM44D4RQKQ>
.
|
Description
When profiling Postgres queries with
EXPLAIN ANALYZE
, it is often necessary to copy the query to the system clipboard in order to feed the output to a visualisation tool like (depesz)[explain.depesz.com].psql
has no facilities for this, so I usually need to do something likeThis is annoying, so I see the advantage of a
\clip
command that copies the DB output to the clipboard, which lets you doIt is different from the native DB commands, so I don't see how to implement it cleanly. It doesn't belong in
pgspecial
. The present implementation is a bit ad hoc. It uses the packagepyperclip
, which implements a cross-platform clipboard client.I am submitting this PR to solicit comments, with the hope to work toward a good solution. Please allow me to run workflows
Checklist
changelog.rst
.AUTHORS
file (or it's already there).pip install pre-commit && pre-commit install
), and ranblack
on my code.