# How to get the number of rows in a table?

**URL:** <https://forum.inductiveautomation.com/t/how-to-get-the-number-of-rows-in-a-table/89648>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [April 29, 2024, 5:16pm UTC](https://forum.inductiveautomation.com/t/how-to-get-the-number-of-rows-in-a-table/89648 "2024-04-29T17:16:36Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [April 29, 2024, 5:16pm UTC](https://forum.inductiveautomation.com/t/how-to-get-the-number-of-rows-in-a-table/89648/1 "2024-04-29T17:16:36Z")

</div>

I am using a query binding, and attempting to use a Script transform to get the number of rows in the dataset, because I did not find a prop on the table that would allow me to get the number of rows.

In the Script console, I can make a dictionary like this:

```python
d = {"name": ["one", "two","three","four"], 
	"number": [1,2,3,4]}

```

Then `print(len(d['name']))` and get `4`.

But, when trying to do the same in a Script transform, I get messages like the index must be an integer, or something about not being able to be coerced into a PyDataSet.

I've tried the `toDataSet` and `toPyDataSet`, to no avail. Such as `len(dataset[0]['name'])`, `len(dataset[0])` evaluates to the number of columns ( I think).

What am I missing? Thanks!

Edit:  
And this:

```python
def transform(self, value, quality, timestamp):
	set1 = len(value)
	return set1

```

Yields: basic streaming dataset has no `len()`.

---

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [April 29, 2024, 5:25pm UTC](https://forum.inductiveautomation.com/t/how-to-get-the-number-of-rows-in-a-table/89648/2 "2024-04-29T17:25:06Z")

</div>

BUT, this seems to work:

```python
def transform(self, value, quality, timestamp):
	set1 = system.dataset.toPyDataSet(value)
	set2 = len(set1)
	return set2

```

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [April 29, 2024, 5:32pm UTC](https://forum.inductiveautomation.com/t/how-to-get-the-number-of-rows-in-a-table/89648/3 "2024-04-29T17:32:11Z")

</div>

You can also do this

```python
headers = ['test']
data = [[1],[2]]
ds = system.dataset.toDataSet(headers, data)
print ds.getRowCount()
print ds.rowCount
pyDs = system.dataset.toPyDataSet(ds)
print pyDs.getRowCount()
print pyDs.rowCount

```

result

```python
>>>
2
2
2
2

```

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [April 29, 2024, 5:32pm UTC](https://forum.inductiveautomation.com/t/how-to-get-the-number-of-rows-in-a-table/89648/4 "2024-04-29T17:32:39Z")

</div>

> [@mdemaris](#):
>
> basic streaming dataset has no `len()`.

You're working with datasets directly, not Python data structures, so the Python builtin `len` has no idea how to work with it. Wrapping with a `PyDataset` is fine; it's no significant performance overhead, but you can also directly ask it for the row count as @dkhayes117 suggested.

---

<div class="post-metadata">

**Author:** ![MSviga](https://avatars.discourse-cdn.com/v4/letter/m/3e96dc/32.png) [@MSviga](https://forum.inductiveautomation.com/u/MSviga)\
**Post date:** [April 30, 2024, 5:56am UTC](https://forum.inductiveautomation.com/t/how-to-get-the-number-of-rows-in-a-table/89648/5 "2024-04-30T05:56:37Z")

</div>

Correct me if im wrong but you should use `ds.rowCount` over `ds.getRowCount()` because "something Jython something" makes it more efficient.

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [April 30, 2024, 6:09am UTC](https://forum.inductiveautomation.com/t/how-to-get-the-number-of-rows-in-a-table/89648/6 "2024-04-30T06:09:57Z")

</div>

> [@MSviga](#):
>
> use `ds.rowCount` over `ds.getRowCount()`

Correct

---

<div class="post-metadata">

**Author:** ![Dharani\_T](https://avatars.discourse-cdn.com/v4/letter/d/bc8723/32.png) [@Dharani\_T](https://forum.inductiveautomation.com/u/Dharani_T)\
**Post date:** [April 30, 2024, 9:07am UTC](https://forum.inductiveautomation.com/t/how-to-get-the-number-of-rows-in-a-table/89648/7 "2024-04-30T09:07:26Z")

</div>

Whats the difference here?

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [April 30, 2024, 9:19am UTC](https://forum.inductiveautomation.com/t/how-to-get-the-number-of-rows-in-a-table/89648/8 "2024-04-30T09:19:07Z")

</div>

`.rowCount` is a bean property with a value that is directly accessible, where as `getRowCount()` is a component method that has to get the value and return it. You could view the method as a middle man between you and the property value.

In practice, it's probably impossible to visually observe the difference in efficiency between the using the property instead of the method, and I've never done any kind of performance testing to confirm the consensus that bean properties are better, but intuitively, it's easy to imagine why one would be more efficient than the other.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 30, 2024, 11:15am UTC](https://forum.inductiveautomation.com/t/how-to-get-the-number-of-rows-in-a-table/89648/9 "2024-04-30T11:15:51Z")

</div>

> [@justinedwards.jle](#):
>
> it's easy to imagine

Fewer instructions in the bytecode for the jython interpreter.

---

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [May 1, 2024, 8:49pm UTC](https://forum.inductiveautomation.com/t/how-to-get-the-number-of-rows-in-a-table/89648/10 "2024-05-01T20:49:47Z")

</div>

Directly, meaning:

```python
query = "myQuery"
ds = system.db.runNamedQuery(query)
print(ds.rowCount)

```

And this does, indeed, work, without converting to any other dataset type.  
Thank you, @dkhayes117 and @paul-griffith
