Data Type Change Question

How do I convert an object into a data number type with an object in it?

test data :

{
  "region": "UK",
  "ts_data": [
    [
      10,
      27
    ],
    [
      10,
      27
    ],
    [
      10,
      27
    ],
    [
      10,
      27
    ],
    [
      10,
      30
    ],
    [
      10,
      30
    ],
    [
      10,
      30
    ],
    [
      10,
      30
    ],
    [
      10,
      30
    ],
    [
      10,
      30
    ],
    [
      10,
      30
    ],
    [
      10,
      30
    ],
    [
      10,
      30
    ],
    [
      10,
      30
    ],
    [
      10,
      30
    ],
    [
      10,
      30
    ],
    [
      10,
      30
    ],
    [
      10,
      30
    ],
    [
      10,
      30
    ],
    [
      10,
      30
    ],
    [
      10,
      30
    ],
    [
      10,
      23
    ],
    [
      10,
      23
    ],
    [
      10,
      23
    ],
    [
      10,
      23
    ],
    [
      10,
      23
    ],
    [
      10,
      23
    ],
    [
      10,
      23
    ],
    [
      10,
      23
    ],
    [
      10,
      23
    ],
    [
      10,
      23
    ]
  ],
  "ts_end": 1375228800000,
  "ts_start": 1372636800000,
  "ts_interval": 86400000
}

Could you give a mock-up example of the output you’re looking for ?

I want ts_data(string) to be marked as ts_data(number) on the screenshot. I want to mark ts_data on the chart

ts_data is an array of arrays containing numbers. This can be coerced into a string but not a number, which is why is appears as such in the charts interface.

You can UNNEST the arrays:

SELECT t.region, elem, t.ts_end, t.ts_interval, t.ts_start
FROM test t
UNNEST t.ts_data AS data
UNNEST data AS elem

which will leave you with “elem” as number. However you lose meaning/distinction between the two nested array elements, so perhaps:

SELECT t.region, data[0] d0, data[1] d1, t.ts_end, t.ts_interval, t.ts_start
FROM test t
UNNEST t.ts_data AS data

is preferable. The two nested array elements will then individually be available as numbers for plotting.

HTH.

It looks like you are using time series data, If using CB 7.20 checkout

SELECT t.region, t.ts_end, t.ts_interval, t.ts_start, d.*
FROM test AS t
UNNEST _timeseries(t) AS d;

Then use graphs. See the example mentioned in the following link

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.