# How to check if a table is not empty

**URL:** <https://community.influxdata.com/t/how-to-check-if-a-table-is-not-empty/12761>\
**Category:** Fluxlang\
**Created:** [January 24, 2020, 4:20pm UTC](https://community.influxdata.com/t/how-to-check-if-a-table-is-not-empty/12761 "2020-01-24T16:20:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aga-Schwarz](https://avatars.discourse-cdn.com/v4/letter/a/a6a055/32.png) [@Aga-Schwarz](https://community.influxdata.com/u/Aga-Schwarz)\
**Post date:** [January 24, 2020, 4:20pm UTC](https://community.influxdata.com/t/how-to-check-if-a-table-is-not-empty/12761/1 "2020-01-24T16:20:11Z")

</div>

is there a way to find out if a from() returned an empty set?

I am working on a larger script with several from() statements returning several tables  
x = from()  
|\> range(…)  
|\> filter(fn: (r ) =\> r.\_measurement == “x” )  
|\> pivot(rowKey:["\_time"], columnKey: ["\_field"], valueColumn: “\_value”)

y = from()  
|\> range(…)  
|\> filter(fn: (r ) =\> r.\_measurement == “y )  
|\> pivot(rowKey:[”\_time"], columnKey: ["\_field"], valueColumn: “\_value”)

z = from()  
|\> range(…)  
|\> filter(fn: (r ) =\> r.\_measurement == “z” )  
|\> pivot(rowKey:["\_time"], columnKey: ["\_field"], valueColumn: “\_value”)

I want to join all the different tables at the end with join(), but it could happen that some of the tables are empty. In this case I want to ignore the empty tables in the join() operation and just join the others.

Unfortunately a join will drop all my results in case any of x,y,z returned an empty set.  
I want to include some conditional logic like

united\_tables = if (exists x) then join(x,y) else y

I have no idea how to implement the “exists x” part. I have tried using the count() function but it will fail, if the original x returned no results. Any way to check if a table is not empty?

---

<div class="post-metadata">

**Author:** ![salvq](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/salvq/32/4252_2.png) [@salvq](https://community.influxdata.com/u/salvq)\
**Post date:** [January 26, 2020, 12:04pm UTC](https://community.influxdata.com/t/how-to-check-if-a-table-is-not-empty/12761/2 "2020-01-26T12:04:22Z")

</div>

@Aga-Schwarz I am worry that there isn’t a way to find out yet, see the similar post here [Return zero 0 when no data from flux query - #2 by scott](https://community.influxdata.com/t/return-zero-0-when-no-data-from-flux-query/12657/2)

But if you found the way to check this I would really very much use this function as well as many times filter does not provide data but following routines expect the data.

Thanks

---

<div class="post-metadata">

**Author:** ![Aga-Schwarz](https://avatars.discourse-cdn.com/v4/letter/a/a6a055/32.png) [@Aga-Schwarz](https://community.influxdata.com/u/Aga-Schwarz)\
**Post date:** [February 7, 2020, 9:39am UTC](https://community.influxdata.com/t/how-to-check-if-a-table-is-not-empty/12761/3 "2020-02-07T09:39:54Z")

</div>

@salvq : Thaks for your insights!

I am not completely sure if this is exactly the same usecase (if I understood your post correctly), as I do not want to return 0 but check for existance within the script. There seems to be a command “exists” supported for values but seems not to be working for streams/ tables:

[https://v2.docs.influxdata.com/v2.0/query-data/guides/exists/](https://v2.docs.influxdata.com/v2.0/query-data/guides/exists/)

Is it known if the “exists” check for tabels/streams will be included in future releases?

---

<div class="post-metadata">

**Author:** ![salvq](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/salvq/32/4252_2.png) [@salvq](https://community.influxdata.com/u/salvq)\
**Post date:** [February 10, 2020, 2:58pm UTC](https://community.influxdata.com/t/how-to-check-if-a-table-is-not-empty/12761/4 "2020-02-10T14:58:22Z")

</div>

@Aga-Schwarz there is no working solution yet for checking if streams / tables are empty.

I would utilize such a function a lot as well also for my use cases. Many times I am getting just an error in Grafana when no streams are coming from Influxdb and I would like to be in control when there is no tables, present error code for instance.

I was checking around however did not find the answer yet when or even if such a feature will be available ☹

---

<div class="post-metadata">

**Author:** ![marcodb](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/marcodb/32/10187_2.png) [@marcodb](https://community.influxdata.com/u/marcodb)\
**Post date:** [May 17, 2022, 10:44pm UTC](https://community.influxdata.com/t/how-to-check-if-a-table-is-not-empty/12761/5 "2022-05-17T22:44:47Z")

</div>

Old thread, but in case someone else lands here looking for answers, an easy way to check for dropped tables (which seems to be more accurate than empty tables given the original example) is:

```auto
isDropped = (tables) => {
	columnsArray = tables
		|> columns()
		|> findColumn(fn: (key) => true, column: "_value")

	return length(arr: columnsArray) == 0
}

```

More details at [Flux: checking for empty and “dropped” tables | by MarcoDB | Medium](https://medium.com/@marcodb.dev/flux-checking-for-empty-and-dropped-tables-f36134b3cd26)
