Skip to main content
Mowi
March 3, 2023
Solved

Transformation SQL - check presence of a key in asset metadata

  • March 3, 2023
  • 2 replies
  • 120 views

Hi all,

what's the best way to write a condition in the transformation query, that checks for presence of certain key in asset metadata?

Example asset metadata:

"KEY": "VALUE"

pseudocode:

select * from _cdf.assets A where ‘KEY’ in A.metadata.keys

 

I’ve been provided with following solutiion by Cognite support, with a note to ask here. Is there a better/other solution?

select * from _cdf.assets 
where metadata['KEY'] is not null;
Best answer by saliha.sajid

Hi @Jerry Dabrowski

Did you mean something like this:

SELECT *
FROM `_cdf`.`assets`
WHERE array_contains(map_keys(metadata), "key-name")

Here are some references:

2 replies

Practitioner ⭐️⭐️⭐️
March 6, 2023

Hi @Jerry Dabrowski

Did you mean something like this:

SELECT *
FROM `_cdf`.`assets`
WHERE array_contains(map_keys(metadata), "key-name")

Here are some references:

Mowi
March 7, 2023

Hi, thank you, it looks this is what I was looking for.