# Empty dataframe from database query

**URL:** <https://discourse.julialang.org/t/empty-dataframe-from-database-query/101745>\
**Category:** General Usage\
**Tags:** question\
**Created:** [July 18, 2023, 5:33pm UTC](https://discourse.julialang.org/t/empty-dataframe-from-database-query/101745 "2023-07-18T17:33:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonjilla](https://avatars.discourse-cdn.com/v4/letter/j/7ba0ec/32.png) [@jonjilla](https://discourse.julialang.org/u/jonjilla)\
**Post date:** [July 18, 2023, 5:33pm UTC](https://discourse.julialang.org/t/empty-dataframe-from-database-query/101745/1 "2023-07-18T17:33:18Z")

</div>

Hello

I have a very common usage pattern for converting the output of a database query (LibPQ for example)

So something like

```julia
data = DataFrame(LibPQ.execute(pgconnection, "select column1,column2 from table1 where condition1 = true"))

```

This generally works quite well, except where the result of the query returns 0 rows. In that case, the schema of the resulting dataframe is not consistent with the schema of the dataframe when there are rows returned from the query

It gets returned like this

```julia
0×2 DataFrame
 Row │ schema data   
     │ CursorSc… Array… 
─────┴───────────────────

```

if I want the value of column1, I get an error since that column doesn’t exist in the 0 row dataframe.

Is there a way to get the output of this query to always have the same DataFrame schema in all cases regardless of query output?

Otherwise, I always have to create a temporary dataframe and check the size before proceding to the next step.

---

<div class="post-metadata">

**Author:** ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Post date:** [July 18, 2023, 6:03pm UTC](https://discourse.julialang.org/t/empty-dataframe-from-database-query/101745/2 "2023-07-18T18:03:49Z")

</div>

> [@jonjilla](#):
>
> Otherwise, I always have to create a temporary dataframe and check the size before proceding to the next step.

This is probably the right thing to do anyway? Just use `isempty(data)` to check.

As for the actual problem, that originates within LibPQ (or Postgres) almost certainly. DuckDB does not behave in this manner.
