sql: support backslash commands with python
Closed this issue · 4 comments
Is your feature request related to a problem? Please describe.
Passing backslash commands through sqlmagic
which in turn uses pgspecial
library throws error
cockroachdb://maxroach:***@roach-0:26257/movr?sslcert=/certs/client.maxroach.crt&sslkey=/certs/client.maxroach.key&sslmode=verify-full&sslrootcert=/certs/ca.crt
cockroachdb://maxroach@roach-0:26257/movr?sslcert=/certs/client.maxroach.crt&sslkey=/certs/client.maxroach.key&sslmode=verify-full&sslrootcert=/certs/ca.crt
(psycopg2.errors.SyntaxError) at or near "\": syntax error
DETAIL: source SQL:
\\dt
^
[SQL: \\dt]
(Background on this error at: http://sqlalche.me/e/f405)
See thread https://cockroachlabs.slack.com/archives/CPD3ANLMB/p1584468085091500
Describe the solution you'd like
Passing \dt
or \?
, etc, commands should result in intended CLI output.
Here's the package in question: https://pypi.org/project/pgspecial/
The problem seems to be this if-statement in ipython-sql
:
if first_word.startswith('\\') and 'postgres' in str(conn.dialect):
if not PGSpecial:
raise ImportError('pgspecial not installed')
pgspecial = PGSpecial()
It will only use pgspecial if postgres
is part of the connection string. But in order to connect to CockroachDB, the connection string must begin with cockroachdb
.
Zendesk ticket #5293 has been linked to this issue.
Closing, since this requires a fix in the ipython-sql project.