# Writing data to dataset tag

**URL:** <https://forum.inductiveautomation.com/t/writing-data-to-dataset-tag/93031>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [July 10, 2024, 7:24pm UTC](https://forum.inductiveautomation.com/t/writing-data-to-dataset-tag/93031 "2024-07-10T19:24:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Josh\_Hoover](https://avatars.discourse-cdn.com/v4/letter/j/65b543/32.png) [@Josh\_Hoover](https://forum.inductiveautomation.com/u/Josh_Hoover)\
**Post date:** [July 10, 2024, 7:24pm UTC](https://forum.inductiveautomation.com/t/writing-data-to-dataset-tag/93031/1 "2024-07-10T19:24:59Z")

</div>

I'm using ignition version 8.1.35 and writing queried data to a dataset tag using system.tag.writeBlocking() and am getting error 'ValueError: Lenght of values does not match length of paths'. I can't seem to figure out why.

I ran the same scrip on version 8.1.39 with no errors and everything worked.

---

<div class="post-metadata">

**Author:** ![michael.flagler](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/michael.flagler/32/26272_2.png) [@michael.flagler](https://forum.inductiveautomation.com/u/michael.flagler)\
**Post date:** [July 10, 2024, 7:27pm UTC](https://forum.inductiveautomation.com/t/writing-data-to-dataset-tag/93031/2 "2024-07-10T19:27:47Z")

</div>

You're going to have to share your script for anyone to help. (Make sure to use a code block when sharing and not a straight copy/paste or screenshot)

Also, per the error, it's saying you don't have a matching number of tags compared to values. These need to be the same count/size.

---

<div class="post-metadata">

**Author:** ![Josh\_Hoover](https://avatars.discourse-cdn.com/v4/letter/j/65b543/32.png) [@Josh\_Hoover](https://forum.inductiveautomation.com/u/Josh_Hoover)\
**Post date:** [July 10, 2024, 7:30pm UTC](https://forum.inductiveautomation.com/t/writing-data-to-dataset-tag/93031/3 "2024-07-10T19:30:48Z")

</div>

I'm not sure what you mean by code block.

---

<div class="post-metadata">

**Author:** ![michael.flagler](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/michael.flagler/32/26272_2.png) [@michael.flagler](https://forum.inductiveautomation.com/u/michael.flagler)\
**Post date:** [July 10, 2024, 7:31pm UTC](https://forum.inductiveautomation.com/t/writing-data-to-dataset-tag/93031/4 "2024-07-10T19:31:53Z")

</div>

Show it as preformatted text using this icon in the toolbar:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/5/9543fda4dff27b38a3b6d5ac043574937c9bdd1f.png)

---

<div class="post-metadata">

**Author:** ![Josh\_Hoover](https://avatars.discourse-cdn.com/v4/letter/j/65b543/32.png) [@Josh\_Hoover](https://forum.inductiveautomation.com/u/Josh_Hoover)\
**Post date:** [July 10, 2024, 7:33pm UTC](https://forum.inductiveautomation.com/t/writing-data-to-dataset-tag/93031/5 "2024-07-10T19:33:52Z")

</div>

```python
db_connection = "postgres"

#grab table name via DieShot tag
tagPath1 = '[default]DieModel'
tagPath2 = '[default]DieShot'
tagPath3 = '[default]Query_Data'

schemaDesignation = system.tag.readBlocking(tagPath1)[0].value
schemaName = 'Die_Model_' + schemaDesignation
tableName = system.tag.readBlocking(tagPath2)[0].value

# Define the query
query = 'SELECT shot, ch1, ch2, ch3, ch4, total, corner FROM "{}"."{}"'.format(schemaName, tableName)

result = system.db.runPrepQuery(query, database=db_connection)

system.tag.writeBlocking(tagPath3, result)

```

---

<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:** [July 10, 2024, 7:41pm UTC](https://forum.inductiveautomation.com/t/writing-data-to-dataset-tag/93031/6 "2024-07-10T19:41:55Z")

</div>

> [@Josh\_Hoover](#):
>
> system.tag.writeBlocking() and am getting error 'ValueError: Lenght of values does not match length of paths'.

`system.tag.writeBlocking()` expects two parameters, a list of tag paths, and a list of tag values. The length of the two lists must match.

Also, you should read both tags at once instead of doing two reads.

```python
db_connection = "postgres"

readPaths = ['[default]DieModel','[default]DieShot']
writePaths = ['[default]Query_Data']

schemaValues = system.tag.readBlocking(readPaths)
schemaDesignation = schemaValues[0].value
schemaName = 'Die_Model_{}'.fomrat(schemaDesignation)
tableName = schemaValues[1].value

query = 'SELECT shot, ch1, ch2, ch3, ch4, total, corner FROM "{}"."{}"'.format(schemaName, tableName)

result = system.db.runPrepQuery(query, database=db_connection)

system.tag.writeBlocking(writePaths, [result])

```

---

<div class="post-metadata">

**Author:** ![Josh\_Hoover](https://avatars.discourse-cdn.com/v4/letter/j/65b543/32.png) [@Josh\_Hoover](https://forum.inductiveautomation.com/u/Josh_Hoover)\
**Post date:** [July 10, 2024, 7:57pm UTC](https://forum.inductiveautomation.com/t/writing-data-to-dataset-tag/93031/7 "2024-07-10T19:57:39Z")

</div>

Thank you for the reply. I know my code could have been cleaner. After implementing changes line by line the issue seems to have been my lack of brackets around 'result' in system.tag.writeBlocking. Thank you for your help.
