0

I am writing measurement to influxdb with InfluxDBClient library

entry = [{
            "time": int((self.end)),
            "measurement": "measurement1",
            "fields": {
                "eventId": self.eventId,
                "start": self.start,
                "end": self.end,
                "lifetime": self.lifetime,
            },

I have noticed that the db is not respecting given order of columns, instead the time is first and then column names in alphabetical order

>SELECT * FROM "measurement1" 
time end eventId hostName lifetime start

How to enforce order given in entry?

Wojtas.Zet
  • 636
  • 2
  • 10
  • 30
  • 2
    I am not sure that it is possible, because server returns JSON and JSON objects (dictionaries) are not strictly ordered. See this answer: https://stackoverflow.com/a/17229462/4265407 – Stanislav Ivanov Oct 14 '20 at 15:20

1 Answers1

1

If your using InfluxQL there is no option to sort the results other than the time field

If you are using flux in then it possible to sort the query results.

from(bucket:"db/rp")
  |> range(start:-12h)
  |> filter(fn: (r) =>
    r._measurement == "system" and
    r._field == "uptime"
  )
  |> sort(columns:["region", "host", "_value"])
robert
  • 8,459
  • 9
  • 45
  • 70