question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SQL errors are discarded when using the pspg pager

See original GitHub issue

Description

I use the following settings in my pgclirc file:

pager = pspg --csv --rr=2 --quit-if-one-screen --ignore-case --csv-header on -s 4 -X
table_format = csv

and I’m quite happy, except for one notable defect: when I execute a query containing an error, pgcli does not properly handle the case and still emit the output coming from PG thru the pager, that simply discards it not being a CSV stream.

For example, not using the pager I get:

$ pgcli -h localhost -u user -d test
Server: PostgreSQL 11.8 (Debian 11.8-1.pgdg90+1)
Version: 3.0.0
Chat: https://gitter.im/dbcli/pgcli
Home: http://pgcli.com
user@localhost:test> select foo;
column "foo" does not exist
LINE 1: select foo
               ^

Time: 0.001s

while going thru pspg this is what I get:

$ pgcli -h localhost -u user -d test --pgclirc my.pgclirc
Server: PostgreSQL 11.8 (Debian 11.8-1.pgdg90+1)
Version: 3.0.0
Chat: https://gitter.im/dbcli/pgcli
Home: http://pgcli.com
user@localhost:test> select foo;
Time: 0.002s

Maybe the _evaluate_command() function should return that success flag to the caller and the latter emit the output without the pager?

Environment

$ pip freeze
cli-helpers==2.1.0
click==7.1.2
configobj==5.0.6
pendulum==2.1.2
-e git+https://github.com/dbcli/pgcli.git@8f7e31450835bca5d9a8bb4de252efba6f4b7b10#egg=pgcli
pgspecial==1.11.10
prompt-toolkit==3.0.5
psycopg2==2.8.4
pudb==2019.2
Pygments==2.6.1
python-dateutil==2.8.1
pytzdata==2020.1
setproctitle==1.1.10
six==1.15.0
sqlparse==0.3.1
tabulate==0.8.7
terminaltables==3.1.0
urwid==2.1.1
wcwidth==0.2.5

$ pspg --version
pspg-2.6.6
with readline (version: 0x0603)
with integrated menu
ncurses version: 6.1, patch: 20190112
ncurses with wide char support
ncurses widechar num: 1
wchar_t width: 4, max: 2147483647
with postgres client integration

The same happens with latest released version of pspg, 3.1.2.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:20 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
okbobcommented, Jun 12, 2021

so 12. 6. 2021 v 11:56 odesílatel Lele Gaifax @.***> napsal:

Yes, I confirm that what @okbob https://github.com/okbob suggested fixes this issue!

To be clear, now my pgclirc contains

pager = pspg --rr=2 --quit-if-one-screen --ignore-case -s 4 -X

table_format = psql

and everything seems working as expected 🎉.

As a side note for @okbob https://github.com/okbob: after looking up the meaning for the --pgcli-fix option you suggest in the pgcli section, it seems redundant without --csv.

I modified pspg readme

Thank you for check

Pavel

Thanks a lot!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/dbcli/pgcli/issues/1200#issuecomment-860030612, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEFO4YR246K2XNDZRE4IU3TSMVK7ANCNFSM4PP3VZLA .

0reactions
lelitcommented, Jun 12, 2021

Yes, I confirm that what @okbob suggested fixes this issue!

To be clear, now my pgclirc contains

pager = pspg --rr=2 --quit-if-one-screen --ignore-case -s 4 -X
table_format = psql

and everything seems working as expected 🎉.

As a side note for @okbob: after looking up the meaning for the --pgcli-fix option you suggest in the pgcli section, it seems redundant without --csv.

Thanks a lot!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Developers - SQL errors are discarded when using the pspg pager -
I use the following settings in my pgclirc file: pager = pspg --csv --rr=2 --quit-if-one-screen --ignore-case --csv-header on -s 4 -X table_format =...
Read more >
How to use pspg for mycli pager - mysql - Stack Overflow
This answer in github works great. In my .my.cnf I added this [client_visidata] pager = pspg -X --quit-if-one-screen. Then use the ...
Read more >
okbob/pspg - Postgres Pager - GitHub
Works well with pgcli too. Can be used as CSV or TSV viewer too. It supports searching, selecting rows, columns, or block and...
Read more >
Documentation: 15: psql - PostgreSQL
Run in single-step mode. That means the user is prompted before each command is sent to the server, with the option to cancel...
Read more >
Tips and tricks - Sourcegraph Handbook
Playbooks for deployments On this page • Playbooks for deployments Playbooks ... a Cloud SQL instance to a previous revision you can use...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found