ipython-sql icon indicating copy to clipboard operation
ipython-sql copied to clipboard

Display column names of table if result is empty

Open psychemedia opened this issue 7 years ago • 0 comments

Hi

With a set up of the form:

PGCONN='sqlite:///test.db'
%load_ext sql
%sql {PGCONN}

and then:

%%sql
DROP TABLE IF EXISTS quickdemo;
CREATE TABLE quickdemo(id INT, name VARCHAR(20), value INT);

a query run in Jupyter notebook using pandas that takes the form:

import sqlite3
c = sqlite3.connect('test.db')

import pandas as pd
pd.read_sql_query('SELECT * from quickdemo;', c)

returns an empty dataframe that displays the column heading but no rows (as desired).

If I run a magic query:

%%sql 
SELECT * from quickdemo;

I just get an empty display (no column names shown).

Is there a way of getting an empty dataframe with column names set if a query returns an empty set of results?

psychemedia avatar Sep 18 '18 13:09 psychemedia