5

I'm using the wonderful ipython-sql

But when I get some data from the database I always see the connection string printed out. See image.

How can I stop the connection string from being shown?

enter image description here

Wolfgang Fahl
  • 15,016
  • 11
  • 93
  • 186
ThatDataGuy
  • 1,969
  • 2
  • 17
  • 43

2 Answers2

4

The extension can handle multiple connections. If you omit the connection string from the magic statement, it wants to tell you which connection the query was applied to (even if you only had one open). But if you include the connection string, then the output won't have the connection string, your statement would need to look like:

%sql postgresql://rl_odin_admin:***@localhost:5432/odin select * from heimdall.vw_time_series_type_v1;

To save typing, you can assign the connection string to a variable, and then use $ in the magic statement, like so:

con = 'postgresql://rl_odin_admin:***@localhost:5432/odin'
%sql $con select * from heimdall.vw_time_series_type_v1;
4

In April 2019 they added a configuration option called displaycon which you can set to False.

%config SqlMagic.displaycon = False

As of 2020-02-20, though, this version isn't in PyPI. To get it to work, I had to clone the repo and install from the source.

! git clone https://github.com/catherinedevlin/ipython-sql.git
! pip install ipython-sql/
# Successfully installed ipython-sql-0.4.0 prettytable-0.7.2 sqlparse-0.3.0