Inconsistent Response Format

If I have a document: {"one":1, "two": 2}

If I make the following query: SELECT bucket.one from bucket, I get the following response: [{"one": 1}]
If I make the following query: SELECT one from bucket, I get the following identical response: [{"one": 1}]

If I make the following query: SELECT bucket.one, bucket.two from bucket, I get the following response: [{"one": 1, "two":2}]
If I make the following query: SELECT one, two from bucket, I get the following identical response: [{"one": 1, "two":2}]

If I make the following query: SELECT bucket.* from bucket, I get the following response: [{"one": 1, "two":2}]

BUT If I make the following query: SELECT bucket.* from bucket, I get the following different response: [{"bucket": {"one":1, "two":2}}]

Which is pretty inconsistent. I’m sure it’s been discussed before, but… Why is * treated special?

@unhuman,

JOSN is no schema (can’t validate fields until document is fetched), To Support JOINs (i.e. multiple sources) the Alias (implicit bucket name or explicit bucket name is included) name added to the document another layer when used *. If that is not included and same field comes from to different sources those are overwritten.

If you don’t need extra layer do this

SELECT b.*
FROM bucket AS b
…;

SELECT a.*, b.*
FROM bucket AS a 
JOIN bucket AS b  ON a.f1 = b.f2;

When multiple sources (JOINS) involved without qualifying the full qualified reference will return error (example: SELECT one, two …).

* means all sources ( CTE variables , FROM , JOIN , LET variables , LETTING variables)

Yeah, that’s what I figured, but there’s still some overwriting that can occur… If I do this (totally contrived) query:
select bucket.*, one as two from bucket;then I get back: [{"one": 1, "two": 2}]

So, there’s still some ignoring / overwriting possible in the shared namespace, but it’s fine… Just something to be aware of.

Thanks for the explanation.

You can name alias field that overwrites. That is under query/application control (by renaming different) vs no control.

Some time overriding has some advantages. Example document has 10 fields and want to project all of them and then one of them recompute and overwrite it will useful in that case.

1 Like