# How to create a 5000 element float array in UDT

**URL:** <https://forum.inductiveautomation.com/t/how-to-create-a-5000-element-float-array-in-udt/44584>\
**Category:** Ignition\
**Created:** [March 17, 2021, 3:46pm UTC](https://forum.inductiveautomation.com/t/how-to-create-a-5000-element-float-array-in-udt/44584 "2021-03-17T15:46:29Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jfan](https://avatars.discourse-cdn.com/v4/letter/j/e8c25b/32.png) [@jfan](https://forum.inductiveautomation.com/u/jfan)\
**Post date:** [March 17, 2021, 3:46pm UTC](https://forum.inductiveautomation.com/t/how-to-create-a-5000-element-float-array-in-udt/44584/1 "2021-03-17T15:46:29Z")

</div>

Hi All,  
I was asked to store 5000 data points from PLC into gateway tags and I wanted to create a big array to store these data. Is there a way to do that in the ignition UDT?

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [March 17, 2021, 3:48pm UTC](https://forum.inductiveautomation.com/t/how-to-create-a-5000-element-float-array-in-udt/44584/2 "2021-03-17T15:48:54Z")

</div>

Is there a reason you want an array to store 5000 data points? What’s your end goal here? I only ask because there may be a better way to do what you are trying to do. I assume you already have 5000 PLC tags, or UDT’s that make up these 5000 data points?

---

<div class="post-metadata">

**Author:** ![jfan](https://avatars.discourse-cdn.com/v4/letter/j/e8c25b/32.png) [@jfan](https://forum.inductiveautomation.com/u/jfan)\
**Post date:** [March 17, 2021, 4:21pm UTC](https://forum.inductiveautomation.com/t/how-to-create-a-5000-element-float-array-in-udt/44584/3 "2021-03-17T16:21:05Z")

</div>

Hi, the end goal is to store data from PLC to our database. Our team was thinking that the first step was to get these data from PLC to gateway and then do a SQL insert to store them into database. Yes, you are correct that I already have the PLC tags.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [March 17, 2021, 5:22pm UTC](https://forum.inductiveautomation.com/t/how-to-create-a-5000-element-float-array-in-udt/44584/4 "2021-03-17T17:22:25Z")

</div>

Is there a reason not to use historian? You can configure the size of change required to be recorded (or you can set it to record all changes/based on a time) and then they are easily used by things like the easy chart.

Alternatively, you can use the gateway tag change event, list your tags you want to be affected by name (possibly by folder) and the script something to record the events.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [March 17, 2021, 6:08pm UTC](https://forum.inductiveautomation.com/t/how-to-create-a-5000-element-float-array-in-udt/44584/5 "2021-03-17T18:08:16Z")

</div>

> [@bkarabinchak.psi](#):
>
> Is there a reason not to use historian?

Usually context. If the 5000 data points are related to a single process or event, then you would want to keep them all together.

Without knowing what the values are for, it's only speculation.

---

<div class="post-metadata">

**Author:** ![jfan](https://avatars.discourse-cdn.com/v4/letter/j/e8c25b/32.png) [@jfan](https://forum.inductiveautomation.com/u/jfan)\
**Post date:** [March 17, 2021, 6:20pm UTC](https://forum.inductiveautomation.com/t/how-to-create-a-5000-element-float-array-in-udt/44584/6 "2021-03-17T18:20:55Z")

</div>

Yes, those data points need to be kept all together to produce a graph later on.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [March 17, 2021, 7:18pm UTC](https://forum.inductiveautomation.com/t/how-to-create-a-5000-element-float-array-in-udt/44584/7 "2021-03-17T19:18:33Z")

</div>

It would be more efficient reading the values directly form the PLC, instead of making 5000 tags.

```python
arraySize = 5000
#path convention in this example is Rockwell-ish
basePLCpath = '[DeviceNameInIgntion]path.to.float.array[%d]'
pathList = [basePLCpath % i for i in xrange(arraySize)]

valuesIn = system.opc.readValues("Ignition OPC UA Server", pathList)

t_stamp = system.date.now()

valuesOut = [] 
for i, value in enumerate(valuesIn):
	valuesOut.extend([t_stamp, i, value])

query = "INSERT INTO table (t_stamp, row, value) VALUES " + ','.join(['(?,?,?)'] * arraySize)

system.db.runPrepUpdate(query, valuesOut, 'dbConnectionName')

```

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [March 17, 2021, 10:57pm UTC](https://forum.inductiveautomation.com/t/how-to-create-a-5000-element-float-array-in-udt/44584/8 "2021-03-17T22:57:54Z")

</div>

I see no reason to do any of this in the PLC. I doubt you actually need 5000 tags. Probably, you are storing the data and then pushing to SQL. Why not just push to SQL as the events occur? No need to store anything in the PLC, except a buffer. Most of us use a FIFO with enough room to cache data, use a transaction group to insert, then on handshake unload the FIFO, rinse and repeat. If data must be kept together, create a UDT.

---

<div class="post-metadata">

**Author:** ![jfan](https://avatars.discourse-cdn.com/v4/letter/j/e8c25b/32.png) [@jfan](https://forum.inductiveautomation.com/u/jfan)\
**Post date:** [March 18, 2021, 4:55pm UTC](https://forum.inductiveautomation.com/t/how-to-create-a-5000-element-float-array-in-udt/44584/9 "2021-03-18T16:55:56Z")

</div>

I was totally wrong about the other method. I think this is a better way, but I wonder if I have 3 identical stations and 4 more data types to read, meaning the total data points will be 5000 times 3 times 5 = 75000 data points, would this method still be applicable and efficient?

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [March 18, 2021, 6:14pm UTC](https://forum.inductiveautomation.com/t/how-to-create-a-5000-element-float-array-in-udt/44584/10 "2021-03-18T18:14:24Z")

</div>

It would be the most efficient, but are all these values really being logged at the same time? How often will they get logged?

---

<div class="post-metadata">

**Author:** ![jfan](https://avatars.discourse-cdn.com/v4/letter/j/e8c25b/32.png) [@jfan](https://forum.inductiveautomation.com/u/jfan)\
**Post date:** [March 18, 2021, 6:31pm UTC](https://forum.inductiveautomation.com/t/how-to-create-a-5000-element-float-array-in-udt/44584/11 "2021-03-18T18:31:01Z")

</div>

Yes it would be ideal if all these values are logged at the same time as lab technicians need these data to create graphs or do calculation after every run. As for how often they get logged, it really depends on the tasks of the day. It is safe to assume we have 10 mins before the next run starts though. We also do not want to lock up the interface as we are writing data to the database. Appreciate your input to this!

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [March 18, 2021, 7:25pm UTC](https://forum.inductiveautomation.com/t/how-to-create-a-5000-element-float-array-in-udt/44584/12 "2021-03-18T19:25:57Z")

</div>

A couple more questions:

- Are all 75000 points for one event, or are we really talking 25000 on three separate events? (i.e three separate test stations doing three separate things)
- Dang, I had another one, but now I can’t think of it. 🙄

Either way, on the surface, it seems like it con be done in 5000 point chunks.

---

<div class="post-metadata">

**Author:** ![jfan](https://avatars.discourse-cdn.com/v4/letter/j/e8c25b/32.png) [@jfan](https://forum.inductiveautomation.com/u/jfan)\
**Post date:** [March 18, 2021, 7:49pm UTC](https://forum.inductiveautomation.com/t/how-to-create-a-5000-element-float-array-in-udt/44584/13 "2021-03-18T19:49:53Z")

</div>

The three stations are running the same test at the same time but they are all collecting their own data points

BTW, ideally I would like my query statement to be like this query = "INSERT INTO tablename (runNumber, equipment, stationID, index, Pressure1, Flow1, Pressure2, Flow2, Flow\_Ratio), VALUES " + ‘,’.join([’(?,?,?,?,?,?,?,?,?)’] \* arraysize)  
I tried to use your code to insert just 10 rows for now to the database but I kept getting errors.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [March 18, 2021, 8:18pm UTC](https://forum.inductiveautomation.com/t/how-to-create-a-5000-element-float-array-in-udt/44584/14 "2021-03-18T20:18:06Z")

</div>

You’ll need to show us your code and errors. I can’t quite see it from here. 😉

Paste your code into your post, highlight it and hit the ‘Preformatted text’ button at the top of the editor.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/c/fcb95557514024ab1e2a7b292a690432bc5d4b23.png)

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [March 18, 2021, 8:26pm UTC](https://forum.inductiveautomation.com/t/how-to-create-a-5000-element-float-array-in-udt/44584/15 "2021-03-18T20:26:26Z")

</div>

I would start with getting rid of the comma before VALUES in the query that I accidently put in my example.

---

<div class="post-metadata">

**Author:** ![chasondeshotel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/chasondeshotel/32/20032_2.png) [@chasondeshotel](https://forum.inductiveautomation.com/u/chasondeshotel)\
**Post date:** [March 18, 2021, 8:32pm UTC](https://forum.inductiveautomation.com/t/how-to-create-a-5000-element-float-array-in-udt/44584/16 "2021-03-18T20:32:55Z")

</div>

> The three stations are running the same test at the same time

> lab technicians need these data to create graphs or do calculation after every run

> runNumber, equipment, stationID, index, Pressure1, Flow1, Pressure2, Flow2, Flow\_Ratio

I'm guessing these runs last a period of time and if that's the case, I would imagine adding a timestamp column would aide in creating graphs

edit: nvm I see `Sample_Num` in your next reply

---

<div class="post-metadata">

**Author:** ![jfan](https://avatars.discourse-cdn.com/v4/letter/j/e8c25b/32.png) [@jfan](https://forum.inductiveautomation.com/u/jfan)\
**Post date:** [March 18, 2021, 8:35pm UTC](https://forum.inductiveautomation.com/t/how-to-create-a-5000-element-float-array-in-udt/44584/17 "2021-03-18T20:35:17Z")

</div>

😁 I found the same thing as well. One thing that stood out to me is that using the for loop to get everything into valuesOut all at once might not work, or I am just bad at this… I had to make the following modification in order for it to work.

```auto
valuesOut = [] 
for i in range (0,3000):
		valuesOut= ([runNumber,equipID, stationID, i, v[0][i], v[1][i], v[2][i], v[3][i], v[4][i]])
		query = "INSERT INTO tablename (runNumber, equipmentID, stationID, Sample_Num, Pressure1_PV, Flow1_PV, Pressure2_PV, Flow2_PV, Flow_Ratio) VALUES " + ','.join(['(?, ?, ?, ?, ?, ?, ?, ?, ?)'])
		system.db.runPrepUpdate(query, valuesOut)		

```

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [March 18, 2021, 9:16pm UTC](https://forum.inductiveautomation.com/t/how-to-create-a-5000-element-float-array-in-udt/44584/18 "2021-03-18T21:16:02Z")

</div>

I remembered my other question! How often does the sampling take place? As mentioned before, many use a FIFO to do the heavy lifting in the PLC. If you can make a UDT on the PLC end that can hold the FIFO data, that may also be an option. The plus side is that you could start logging data right away from the beginning of the test.

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [March 18, 2021, 11:58pm UTC](https://forum.inductiveautomation.com/t/how-to-create-a-5000-element-float-array-in-udt/44584/19 "2021-03-18T23:58:27Z")

</div>

You are really making this more difficult than it needs to be. As I thought, each test doesn’t need 5000 points. Dump that idea and move to a simpler approach.

Start with the data, is the data categories always the same per station? If so, then add a column for station ID and as stated add a timestamp. Then you can query all day long and graph to your hearts content.

If you knew the basic understanding you would have never suggested 5000 points.

---

<div class="post-metadata">

**Author:** ![jfan](https://avatars.discourse-cdn.com/v4/letter/j/e8c25b/32.png) [@jfan](https://forum.inductiveautomation.com/u/jfan)\
**Post date:** [March 19, 2021, 12:17am UTC](https://forum.inductiveautomation.com/t/how-to-create-a-5000-element-float-array-in-udt/44584/20 "2021-03-19T00:17:51Z")

</div>

The PLC scan rate for these data is much faster than the scan rate in ignition which is why we needed to read and write all the data after the test. Also, we already have UDTs in the PLC to store all the data if this is what you meant. I just need to move them into the database.

[Next page](https://forum.inductiveautomation.com/t/how-to-create-a-5000-element-float-array-in-udt/44584.md?page=2)
