Inserting tag value into database table

i want to add tag values in dattabse table …my table name is historian_table_2021 and my column name is float_value…i tried many scripts but i am getting error…can anyone suggest some solution.

Hi @vani161998, what is the error you are getting? Also, what version of Ignition are you using?

ignition8.0 version

traceback (most recent call last):
File “”, line 14, in
at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.error(AbstractDBUtilities.java:362)

at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.runPrepUpdate(AbstractDBUtilities.java:258)

at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.base/java.lang.reflect.Method.invoke(Unknown Source)

java.lang.Exception: java.lang.Exception: Error executing system.db.runPrepUpdate(INSERT INTO historian_table_2021 (float_value) VALUES (tag), [set([’[E10190_PWRP_LN_EMDG1]EXHAUST GAS TEMP/SNA0_1T019PV (A1)/ANALOG TEMP’])], , , false, false)

It looks like it’s trying to pass the tag path rather than the value of the tag. What does your print return?

Also, read has been depreciated. readBlocking() or readAsync() are the preferred functions for reading tags for v8+.

For example:

tagname = system.tag.readBlocking(["[E10190_PWRP_LN_EMDG1]EXHAUST GAS TEMP/SNA0_1T019PV (A1)/ANALOG TEMP"])

print statement returns the tag value… i can read the value but it is not getting reflected in database table.

What is the tag value?

56.0

[[56.0, Good, Tue Jun 08 12:48:27 IST 2021 (1623136707087)]]

Your error doesn’t match up to your code. Looks like it’s from your first attempt above.

tagname = '[E10190_PWRP_LN_EMDG1]EXHAUST GAS TEMP/SNA0_1T019PV (A1)/ANALOG TEMP'

value = system.tag.readBlocking([tagname])[0].value

query = 'INSERT INTO historian_table_2021 (float_value) VALUES (?)'

system.db.runPrepUpdate(query, [value])
2 Likes