Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Optionally flatten a query that results in a object with a single field into a simple array #1326

Closed
2 tasks done
Du-z opened this issue Oct 6, 2022 · 3 comments
Closed
2 tasks done
Assignees
Labels
feature New feature or request
Milestone

Comments

@Du-z
Copy link

Du-z commented Oct 6, 2022

Is your feature request related to a problem?

Currently the query SELECT name FROM user would result in something like the following.

[
  {
    "Name": "Name 1"
  },
  {
   "Name": "Name 2"
  }
]

However it would be far easier to deserialize and work with a simple string array.

[
  "Name 1",
  "Name 2"
]

Describe the solution

An example of this being implemented is with CosmosDB's FIELD keyword
SELECT VALUE name FROM user

Alternative methods

I don't have any other examples of how this could be done

SurrealDB version

1.0.0-beta.8+20220930.c246533

Contact Details

No response

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct
@Du-z Du-z added feature New feature or request triage This issue is new labels Oct 6, 2022
@mathe42
Copy link

mathe42 commented Oct 6, 2022

I think a simple function array::flatten(...) should solve that. See #1308 for a PR.

@Du-z
Copy link
Author

Du-z commented Oct 6, 2022

Hi, I considered if a function like array::flatten(...) would be suitable before making this issue and the outputs will be subtly different.

SELECT array::flatten(name) FROM user WHERE emailValidated = true will not result in a array of string. But instead will result in an array of objects that has a field with the type of string.

@mathe42
Copy link

mathe42 commented Oct 6, 2022

Ah yes missread the issue - sorry.

Also in my mind it was

array::flatten(SELECT name FROM user WHERE emailValidated = true)

@tobiemh tobiemh removed the triage This issue is new label Oct 15, 2022
@tobiemh tobiemh added this to the v1.0.0-beta.9 milestone Oct 15, 2022
AL1L added a commit to AL1L/surrealdb that referenced this issue Dec 26, 2022
@tobiemh tobiemh self-assigned this Feb 12, 2023
phughk pushed a commit to phughk/surrealdb that referenced this issue Mar 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants