首先
%%sql postgresql:///countries
然后
select xxx;
And after the first connection to the database, the connection code (postgresql:///countries) can be omitted. the single % this time.
%SQL select xxx (%和SQL之间没有空隙 SQL和select要写在同一排)
更多的差别见documentation
(https://github.com/catherinedevlin/ipython-sql#pandas)
We can even convert our SQL results to a pandas DataFrame! Let's convert the entire countries table.
SQL Query
result = %sql SELECT * FROM countries;
To pandas DataFrame
df = result.DataFrame()
df.info()
先储存,再用.DataFrame() 功能变成df
SQLAlchemy也能在J里使用SQL