Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display column names of table if result is empty #125

Open
psychemedia opened this issue Sep 18, 2018 · 0 comments
Open

Display column names of table if result is empty #125

psychemedia opened this issue Sep 18, 2018 · 0 comments

Comments

@psychemedia
Copy link

psychemedia commented Sep 18, 2018

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?

pmfischer pushed a commit to pmfischer/ipython-sql that referenced this issue Sep 8, 2023
* running nbqa during CI, formatting notebooks

* linting in two steps
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant