In-query referring to object property by another variable\property value

Hi good people of couchbasia

was looking at some of the object functions but could not find something that could help me obtain the value of a property (in my case the property name is a guid string with ‘-’, therefore is problematic to use as a regular property name)

was wondering about expected behavior, is this a expected/version issue/unknown ?
maybe some thoughts about how can i address the issue ?

FROM ([1]) a LET
x = ([{‘name’: ‘me_prop’, ‘me_prop’: ‘me_prop_val’}]),
y = ({‘name’: ‘me_prop’, ‘me_prop’: ‘me_prop_val’})
x[0].name as arr_obj_with_named_prop_as_key,
x[0][x[0].name] as arr_obj_with_variable_as_key,
x[0][‘me_prop’] as arr_obj_with_str_val_as_key, as obj_with_named_prop_as_key,
y[] as obj_with_variable_as_key,
y[‘me_prop’] as obj_with_str_val_as_key

“arr_obj_with_named_prop_as_key”: “me_prop”,
“arr_obj_with_str_val_as_key”: null,
“arr_obj_with_variable_as_key”: null,
“obj_with_named_prop_as_key”: “me_prop”,
“obj_with_str_val_as_key”: null,
“obj_with_variable_as_key”: null

as always, many thanks and keep up with your amazing work

Hi @mazorsk,

If you have guid - that consider as special character you should use escaped identifier with back ticks

{"a-b": 10}   
 Access with     `a-b` 
SELECT AS name_key
       d.[] AS name_key_val
FROM [{"name": "me_prop", "me_prop": "me_prop_val"}]  AS d;

d.[] There is dot before ARRAY bracket (dictionary access) . It evaluate (must produce string) use that string from as field name i.e d.[] ===> d.me_prop

FROM ([1]) a LET
x = ([{‘name’: ‘me_prop’, ‘me_prop’: ‘me_prop_val’}]),
y = ({‘name’: ‘me_prop’, ‘me_prop’: ‘me_prop_val’})
x[0].name as arr_obj_with_named_prop_as_key,
x[0].[x[0].name] as arr_obj_with_variable_as_key,
x[0].me_prop  as arr_obj_with_str_val_as_key, as obj_with_named_prop_as_key,
y.[] as obj_with_variable_as_key,
y.me_prop  as obj_with_str_val_as_key

thanks a lot!
seriously tho, i love you people. amazing product, best db ever-ever. :slight_smile: