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.

pgcli silently fails if there's an error

See original GitHub issue

Description

I’m trying to run an INSERT command that fails, but pgcli doesn’t show any errors; example:

I create the following table:

create table my_table(col1 varchar(10) not null, col2 varchar(10))

Then, I try to do an invalid insertion:

insert into my_table(col2) values('should fail')

But pgcli doesn’t show any errors and only shows:

my_db> insert into my_table(col2) values('should fail');
Time: 0.004s

Which gives the impression that the insertion worked and we’re good to go.

Whereas trying something similar with psql would give these errors:

my_db=# insert into my_table(col2) values('should fail');
ERROR:  value too long for type character varying(10)

my_db=# insert into my_table(col2) values('shouldfail');
ERROR:  null value in column "col1" violates not-null constraint
DETAIL:  Failing row contains (null, shouldfail).

Your environment

  • Please provide your OS and version information. Manjaro Linux
  • Please provide your CLI version. Version: 3.1.0
  • What is the output of pip freeze command. not sure if this is helpful, but let me know and I can provide it

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
farzadmfcommented, Jul 22, 2021

Very nice @lelit , thank you so much. Summary of what I did (in case people see this in the future):

  • Removed --pgcli-fix and --csv from pspg options
  • Set table_format = psql (the default)

After this, the table borders didn’t look at pretty as before, so I added --force-uniborder to pspg, and now I see the errors, super nice 💯

Closing this issue since, as far as I’m concerned, my issue is solved (thank you @lelit again)

And thank you @amjith for following up with this

1reaction
amjithcommented, Jul 21, 2021

Can you enable debug logging in pgcli? You can do that via the config file in ~/.config/pgcli/config change the log_lever to DEBUG.

Run the above commands and check the log file: ~/.config/pgcli/log. I see the following in my pgcli log file:

2021-07-21 08:53:08,697 (736377/MainThread) pgcli.pgbuffer DEBUG - Not in multi-line mode. Handle the buffer.
2021-07-21 08:53:08,700 (736377/MainThread) pgcli.key_bindings DEBUG - Detected enter key.
2021-07-21 08:53:08,756 (736377/MainThread) pgcli.main DEBUG - sql: "insert into my_table(col2) values('should fail');"
2021-07-21 08:53:08,771 (736377/MainThread) pgcli.pgexecute DEBUG - Trying a pgspecial command. sql: "insert into my_table(col2) values('should fail')"
2021-07-21 08:53:08,771 (736377/MainThread) pgcli.pgexecute DEBUG - Regular sql statement. sql: "insert into my_table(col2) values('should fail')"
2021-07-21 08:53:08,773 (736377/MainThread) pgcli.pgexecute ERROR - sql: "insert into my_table(col2) values('should fail')", error: StringDataRightTruncation('value too long for type character varying(10)\n')
2021-07-21 08:53:08,782 (736377/MainThread) pgcli.pgexecute ERROR - traceback: 'Traceback (most recent call last):\n  File "/home/amjith/Dropbox/code/python/pgcli/pgcli/pgexecute.py", line 472, in run\n    yield self.execute_normal_sql(sql) + (sql, True, False)\n  File "/home/amjith/Dropbox/code/python/pgcli/pgcli/pgexecute.py", line 507, in execute_normal_sql\n    cur.execute(split_sql)\n  File "/home/amjith/Dropbox/code/python/pgcli/pgcli/pgexecute.py", line 168, in execute\n    psycopg2.extensions.cursor.execute(self, sql, args)\npsycopg2.errors.StringDataRightTruncation: value too long for type character varying(10)\n\n'
2021-07-21 08:53:08,782 (736377/MainThread) pgcli.main DEBUG - headers: None
2021-07-21 08:53:08,782 (736377/MainThread) pgcli.main DEBUG - rows: None
2021-07-21 08:53:08,782 (736377/MainThread) pgcli.main DEBUG - status: '\x1b[31mvalue too long for type character varying(10)\n\x1b[0m'
2021-07-21 08:53:10,319 (736377/ThreadPoolExecutor-0_0) pgcli.pgcompleter DEBUG - Suggestion type: <class 'pgcli.packages.sqlcompletion.Keyword'>
2021-07-21 08:53:10,324 (736377/ThreadPoolExecutor-0_0) pgcli.pgcompleter DEBUG - Suggestion type: <class 'pgcli.packages.sqlcompletion.Special'>

Read more comments on GitHub >

github_iconTop Results From Across the Web

psql command is failing silently - Stack Overflow
If you want to use a “here document” with psql , do this: psql "$pg_cp_prod_conn_str" <<EOF ALTER TABLE cp_user_emails ADD CONSTRAINT ...
Read more >
Install - pgcli
Check if pip is installed on the system. $ which pip. If the above command returns an error, then you do not have...
Read more >
Insert statement fails silently when a FK constaint can't be ...
My bet is that: SELECT id FROM entity WHERE properties->>'member_id' = '92385'. returns NO ROWS (NO ERROR) and INSERT command is never ...
Read more >
Documentation: 15: 43.9. Errors and Messages - PostgreSQL
Use the RAISE statement to report messages and raise errors. ... After level if any, you can specify a format string (which must...
Read more >
pip install psql
If it is installed then you can do: $ pip install pgcli. ... OS, and Python version used there are several possible errors...
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