SQL database ID column not iterable

Hi, I’m trying to access a dataset object that I created in a script. The object is made up of the row id’s from a sql table. Here is the code:

  for row in dataset:
dBdeviceID = row[3]

I want to take the rows from this set and add them to an array so that I can use them in another part of my script but every time I try to access the “dBdeviceID” set I get an error saying it is imutable, that it can’t be iterated over etc. Does anyone know how to do this?


Thanks

Is it a dataset or Pydataset?

https://docs.inductiveautomation.com/display/DOC79/Datasets

It is a Pydataset that was converted from an ignition dataset.

In the code that you posted you are repeatedly assigning a value to the variable dBdeviceID.

If dBdeviceID is defined as an array or a list you should use append().

for row in dataset:
    dBdeviceID.append(row[3])

Or use a list comprehension one-liner:

Column3 = [row[3] for row in dataset]

If the original dataset inherits from an AbstractDataset (likely), you can skip the conversion and do this:

Column3 = list(originalDS.getColumnAsList(3))

The latter is blistering fast, if that matters in your case.

2 Likes