如何从 ipython-sql 输出中删除连接字符串信息?

How to remove connection string info from ipython-sql output?

我用的很精彩ipython-sql

但是当我从数据库中获取一些数据时,我总是看到打印出的连接字符串。见图像。

如何停止显示连接字符串?

扩展程序可以处理多个连接。如果您从魔术语句中省略连接字符串,它会告诉您查询应用于哪个连接(即使您只打开了一个连接)。但是如果你包含连接字符串,那么输出将没有连接字符串,你的语句需要看起来像:

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

为了节省输入,您可以将连接字符串分配给一个变量,然后在魔术语句中使用 $,如下所示:

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

2019 年 4 月,他们添加了一个名为 displaycon 的配置选项,您可以将其设置为 False

%config SqlMagic.displaycon = False

不过,截至 2020 年 2 月 20 日,此版本不在 PyPI 中。为了让它工作,我必须克隆 repo 并从源安装。

! 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