Hi everyone,
I’m working with CrateDB 5.10.11 and I’m having trouble accessing nested object keys in my queries. I keep getting this error:
UnsupportedFeatureException[Can’t handle Symbol [SimpleReference: fields[‘aenergy’][‘total’]]]
My table structure:
I have a table called shelly_metrics with the following structure:
-
ts - timestamp when the record was created
-
measurement - string (I only need records with “shelly”)
-
tags - an object, I need records where tags[‘context’] = ‘status.switch:0’
-
fields - an object containing nested data, I need the value fields[‘aenergy’][‘total’] (watt) which is a float
What I’m trying to do:
I want to calculate the sum of watt differences for a given time period and a specific MAC address (tags[‘mac’]). The watt value is normally an increasing number, so I need to calculate the difference between consecutive records and sum those differences. If the previous value is greater than the next one, the difference should be 0, not a negative number.
The problem:
When I try to access fields[‘aenergy’][‘total’] directly in my query, CrateDB throws the error above. It seems like CrateDB doesn’t support nested object key access.
Example of what I’m trying to do:
SELECT
tags['mac'] as mac_address,
SUM(
CASE
WHEN LAG(CAST(fields['aenergy']['total'] AS DOUBLE)) OVER (
PARTITION BY tags['mac']
ORDER BY ts
) IS NULL THEN 0.0
WHEN CAST(fields['aenergy']['total'] AS DOUBLE) > LAG(CAST(fields['aenergy']['total'] AS DOUBLE)) OVER (
PARTITION BY tags['mac']
ORDER BY ts
) THEN
CAST(fields['aenergy']['total'] AS DOUBLE) - LAG(CAST(fields['aenergy']['total'] AS DOUBLE)) OVER (
PARTITION BY tags['mac']
ORDER BY ts
)
ELSE 0.0
END
) as total_watt_hours
FROM shelly_metrics
WHERE measurement = 'shelly'
AND tags['context'] = 'status.switch:0'
AND tags['mac'] = 'AA:BB:CC:11:22:33'
AND ts >= '2025-08-19T00:00:00Z'
AND ts <= '2025-08-19T23:59:59Z'
GROUP BY tags['mac'];
What I’ve tried:
-
Direct nested key access: fields[‘aenergy’][‘total’]

-
UNNEST: Only works for arrays, not nested objects

Sample data structure:
{
“ts”: “2025-08-19T10:00:00Z”,
“measurement”: “shelly”,
“tags”: {
"mac": "88:13:bf:d9:b1:5c", "context": "status.switch:0"
},
“fields”: {
"aenergy": {
"total": 1234.56
}
}
}
Questions:
- How can I access nested object keys like fields[‘aenergy’][‘total’] in CrateDB 5.10.11?
- Is there a specific syntax or function I should be using?
- Are there any workarounds for this limitation?
Any help would be greatly appreciated! Thanks in advance.
Volker.