SELECT `value`.`net` AS `somethingElse`.`net` FROM fooBucket;
Why is that? If I select a sub-document, then what comes back preserves structure, but I can’t re-name or change that structure with an alias? Indeed it looks like even if I alias it to itself (i.e. ```SELECT value.net AS value.`net````) it doesn’t work, saying “syntax error at .”. If you alias, must the name always be “flat”?
SELECT
@city,
meta(@city).id AS city.id,
@mayor AS city.mayor,
meta(@mayor).id AS city.mayor.id
FROM `odm-test` AS city
JOIN `odm-test` AS mayor ON KEYS city.mayorId
WHERE city.type = "city" AND mayor.type = "mayor"
LIMIT 1
SELECT
object_put(
object_put(@city, "id", meta(@city).id),
"mayor", object_put(@mayor, "id", meta(@mayor).id))
as city
FROM `odm-test` AS city
JOIN `odm-test` AS mayor ON KEYS city.mayorId
WHERE city.type = "city" AND mayor.type = "mayor"
LIMIT 1
Got it, thanks. We would need a general syntax to combine objects and arrays, which would be usable beyond projections and aliases. We will keep that in mind. For example:
SELECT
city ++
{
meta(city).id,
"mayor": mayor ++ { city.mayor.id }
} AS city
FROM `odm-test` AS city
JOIN `odm-test` AS mayor ON KEYS city.mayorId
WHERE city.type = "city" AND mayor.type = "mayor"
LIMIT 1;
SELECT
city ++
{
"id": meta(city).id,
"mayor": mayor ++ { "id": meta(mayor).id }
} AS city
FROM `odm-test` AS city
JOIN `odm-test` AS mayor ON KEYS city.mayorId
WHERE city.type = "city" AND mayor.type = "mayor"
LIMIT 1
It seems more complex to read without any benefits, no ?
I was not suggesting an exact syntax. I was just framing the issue. We need a syntax for combining objects and arrays. It must work anywhere that objects and arrays can appear. It cannot be specific to, or limited to, aliases and projections.
Using functions to combine objects and arrays is a bit verbose, and more concise syntax would be nice.
SELECT
meta(mayor).id AS mayor.id,
city ++
{
"id": meta(city).id,
"mayor": mayor
} AS city
FROM `odm-test` AS city
JOIN `odm-test` AS mayor ON KEYS city.mayorId
WHERE city.type = "city" AND mayor.type = "mayor"
LIMIT 1
We added one step. For the next step, I am thinking we could support concatenation ( || ) of objects and of arrays.
Here is what we added:
SELECT
OBJECT_CONCAT( city, { META(city).id }, { "mayor": OBJECT_CONCAT( mayor, { META(mayor).id } ) } ) AS city
FROM `odm-test` AS city
JOIN `odm-test` AS mayor ON KEYS city.mayorId
WHERE city.type = "city" AND mayor.type = "mayor"
LIMIT 1
;