# Best Way to Initialize Empty DataSet with Column Types

**URL:** <https://forum.inductiveautomation.com/t/best-way-to-initialize-empty-dataset-with-column-types/86316>\
**Category:** Ignition\
**Tags:** ignition81, scripting\
**Created:** [February 24, 2024, 10:07pm UTC](https://forum.inductiveautomation.com/t/best-way-to-initialize-empty-dataset-with-column-types/86316 "2024-02-24T22:07:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brandon\_Peterson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/brandon_peterson/32/32960_2.png) [@Brandon\_Peterson](https://forum.inductiveautomation.com/u/Brandon_Peterson)\
**Post date:** [February 24, 2024, 10:07pm UTC](https://forum.inductiveautomation.com/t/best-way-to-initialize-empty-dataset-with-column-types/86316/1 "2024-02-24T22:07:54Z")

</div>

What's the best way to create an empty DataSet with the column types set?

**Possible ideas**

```py
myDataset = system.dataset.toDataSet(['intCol', 'strCol'], [[1, 'a']])
myDataset = system.dataset.clearDataset(myDataset)

```

```py
myDataset = system.dataset.toDataSet([], [])
myDataset = system.dataset.addColumn(myDataset, 0, [], 'intCol', int)
myDataset = system.dataset.addColumn(myDataset, 1, [], 'strCol', str)

```

I know DataSets are designed to be immutable, which is why I don't like either of these methods.

- Is there a better way to do this?
- Have I already found the best way to do this?
- Might this be an indication that I've done something else wrong along the way?
  - Maybe I just shouldn't be trying to initialize DataSets at all?

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [February 24, 2024, 10:25pm UTC](https://forum.inductiveautomation.com/t/best-way-to-initialize-empty-dataset-with-column-types/86316/2 "2024-02-24T22:25:21Z")

</div>

If you truly need an empty dataset, then use a `DatasetBuilder`.

> **[DatasetBuilder](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.37/com/inductiveautomation/ignition/common/util/DatasetBuilder.html)**
>
> declaration: package: com.inductiveautomation.ignition.common.util, class: DatasetBuilder

Honestly though, without knowing exactly what you're trying to accomplish, I would say that I have never had a need in 7 years to "initialize" an empty dataset.

---

<div class="post-metadata">

**Author:** ![Brandon\_Peterson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/brandon_peterson/32/32960_2.png) [@Brandon\_Peterson](https://forum.inductiveautomation.com/u/Brandon_Peterson)\
**Post date:** [February 24, 2024, 10:51pm UTC](https://forum.inductiveautomation.com/t/best-way-to-initialize-empty-dataset-with-column-types/86316/3 "2024-02-24T22:51:27Z")

</div>

The project I'm working with has some session properties that are sometimes set to a dataset, sometimes set to a string. On loading a relevant page, I want that session prop to be an empty dataset with the appropriate columns and types preset. I thought it'd be easier to just create one from scratch instead of ensuring that prop isn't set to a string from anywhere else in the project.

Writing this down explicitly is making me second guess that decision lol. But that was the motivation for this post.

---

<div class="post-metadata">

**Author:** ![Brandon\_Peterson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/brandon_peterson/32/32960_2.png) [@Brandon\_Peterson](https://forum.inductiveautomation.com/u/Brandon_Peterson)\
**Post date:** [February 24, 2024, 10:55pm UTC](https://forum.inductiveautomation.com/t/best-way-to-initialize-empty-dataset-with-column-types/86316/4 "2024-02-24T22:55:29Z")

</div>

For future reference:

I found an even simpler way to create a dataset the way I want to. There's a constructor on the BasicDataset class that has exactly what I need:

```py
from com.inductiveautomation.ignition.common import BasicDataset

myDataset = BasicDataset(['intCol', 'strCol'], [int, str])

```

From the [`BasicDataset`](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.37/com/inductiveautomation/ignition/common/BasicDataset.html#%3Cinit%3E(java.util.List,java.util.List)) documentation.

---

<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:** [February 24, 2024, 11:34pm UTC](https://forum.inductiveautomation.com/t/best-way-to-initialize-empty-dataset-with-column-types/86316/5 "2024-02-24T23:34:19Z")

</div>

If you want to use a binding, my unionAll() expression function can do this without jython.
