readBlocking multiple tags and DB insert

The readBlocking example in the docs shows using a for loop.

If doing a multi-column DB insert of these values, what is the best method?

I can think of a crude one using if, elif statements. I bet someone has a nice one-liner.

I'm only working with a couple of tags for testing now and I will only be adding a few more. I don't mind manually adding extra ? into the Prep query at this stage. I know if it was many tags and subject to a lot of change, Phil etc have provided nice examples of dynamic building of ? based on the length of items.

8.1.25, Gateway Timer Script

This is entirely dependent on your table structure. Show more of what you are trying to achieve.

Wide table, index AI, multiple columns and a datetime with CURRENT_TIMESTAMP(). (MariaDB).

The multiple columns are all floats. 1-second granularity.

I've done similar in past with 79, looking for guidance on the most efficient 81 methods with readBlocking etc.

If you are just using the values, a one-liner would be something like:

tagList = ['[provider]path/to/tag1',
          '[provider]path/to/tag2',
          '[provider]path/to/tag3',
          ...
          '[provider]path/to/tagN'
         ]

values = [qValue.value for qValue in system.tag.readBlocking(tagList)]

However, if you also need to iterate over something else, (example: generate the column names from the last portion of the tag path), it becomes more efficient to use a for loop and zip:

tagList = ['[provider]path/to/tag1',
           '[provider]path/to/tag2',
           '[provider]path/to/tag3',
           ...
           '[provider]path/to/tagN'
          ]

colNames = values = []

for tag, qValue in zip(tagList, system.tag.readBlocking(tagList)):
	colNames.append(tag.split('/')[-1])
	values.append(qValue.value)
1 Like

you can also do like this ,

path = ["[provider]path/to/tag1",
"[provider]path/to/tag2"]
qualifiedValues = system.tag.readBlocking(path)
print qualifiedValues
print list(map(lambda x : x.value,qualifiedValues))