I want to join InfluxDB 2.0 data with PostgreSQL data. The date times in InfluxDB are not the same as in PostgreSQL (only date, no time) and also the symbol differs (PostgreSQL = ‘TGET.AS’, InfluxDB = (‘Adj Close’, ‘TGET.AS’)).
In this case I have stock data in PostgreSQL and prices in InfluxDB. I want to calculate the value on a given day (amount from PostgreSQL, price from InfluxDB).
The Flux code:
import “sql”
portefeuille = sql.from(
driverName: “postgres”,
dataSourceName: “postgresql://user@host/database”,
query: “select datum,symbool,aantal from portefeuille_vw”
)
koersen = from(bucket: “pfs”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: ® => r["_measurement"] == “koersen”)
|> filter(fn: ® => r["_field"] == “(‘Adj Close’, ‘TGET.AS’)”)
|> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
|> yield(name: “mean”)
join(tables: {metric: portefeuille, info: koers}, on: ???)