如何通过Google-colaboratory连接到heroku上的Postgresql数据库? [英] How can you connect to a postgresql database on heroku from google-colaboratory?

查看:88
本文介绍了如何通过Google-colaboratory连接到heroku上的Postgresql数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚开始使用colaboratory,并且想对postgresql数据库运行sql查询.请问这有可能吗?我已经将魔术sql与jupyter nb结合使用了.

Just started using colaboratory and would like to run sql queries against a postgresql db. Is this possible on colaboratory. I've used magic sql with jupyter nb to do this.

推荐答案

这是使用2 %%而不是1%的问题,这给了我一个错误.我正在运行的是这样的:

It was a matter of using 2 %% instead of 1 that was giving me an error. What I'm running is this:

! pip install ipython-sql
! pip install psycopg2 
%sql postgres://<connect string>
%sql select tablename from pg_tables;

我看到了一个示例,其中使用%% sql运行sql,当我尝试出现错误时. 现在一切都运行良好. 丽贝卡

I saw an example where there sql was run with %%sql and when I tried that I got an error. Everything is running well now. Rebecca

这篇关于如何通过Google-colaboratory连接到heroku上的Postgresql数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆