问题
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.
回答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;
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
来源:https://stackoverflow.com/questions/47216559/how-can-you-connect-to-a-postgresql-database-on-heroku-from-google-colaboratory