Hi,
I have the below code in influx
import “sql” // Fetch data from PostgreSQL tag_names = sql.from( driverName: “postgres”, dataSourceName: “postgres:url sslmode=disable”, query: “SELECT tag,value FROM sample_tags WHERE tag = ‘tag1’” )
// Fetch data from InfluxDB
t1 = from(bucket: “Sample_Prod”)
|> range(start: -5m)
|> filter(fn: (r) => r[“_measurement”] == “Sample” and r[“tag”] == “tag1”)
|> filter(fn: (r) => r[“state”] == “HP”)
|> filter(fn: (r) => r[“plant_code”] == “code1”)
|> last()
|> map(fn: (r) => ({ r with _value: float(v: r._value) }))
|> group()
|> drop(columns:[“_start”, “_stop”, “_measurement”, “_field”, “tag”])
// Check if data exists in InfluxDB
|> map( fn: (r) => ({r with find:if exists r._value then “t1” else “tag_names”, }), )
|> yield()
If tag1 is available in t1 then display tag1 and its value else display tag and its value from postgressql