hasura / graphql-engine

Blazing fast, instant realtime GraphQL APIs on your DB with fine grained access control, also trigger webhooks on database events.
https://hasura.io
Apache License 2.0
31.18k stars 2.77k forks source link

Case insensitive order_by #5564

Open bertyhell opened 4 years ago

bertyhell commented 4 years ago

Is there a way to order_by but case insensitive without having to add a new property?

eg this dataset:

subjects: [
  {
    description: "English"
  },
  {
    description: "math"
  },
  {
    description: "alchemy"
  },
]

We would like to fetch these alphabetically sorted:

{
  subjects(order_by: {description: asc}) {
    description
  }
}

We get:

[
  {
    description: "English"
  },
  {
    description: "alchemy"
  },
  {
    description: "math"
  },
]

Maybe adding an iorder_by property, similar to ilike so we get this result:

[
  {
    description: "alchemy"
  },
  {
    description: "English"
  },
  {
    description: "math"
  },
]
wwwdepot commented 4 years ago

Just make a custom function with ORDER BY lower(description)

nawgz commented 3 years ago

@wwwdepot How can I do that? I do not understand and from looking thru the Hasura API Reference I see no further mention to this. Is it something I can do as part of my GraphQL query or do I have to do something cumbersome like create a view or a custom SQL function?

idesignpixels commented 3 years ago

Also having an issue with this was hoping for something like asc, ciasc (case insensitive ascending) or something similar

jflambert commented 2 years ago

Just make a custom function with ORDER BY lower(description)

How is this helpful? We can't order by custom functions in graphql.

@rikinsk any progress on adding asc/iasc/desc/idesc sort options? Do you have a workaround?

bertyhell commented 2 years ago

currently we solved this by creating a computed column in hasura with the lowercase equivalent of the other column: https://hasura.io/docs/latest/graphql/core/databases/postgres/schema/computed-fields.html image

jflambert commented 2 years ago

@bertyhell smart!!! but I'd have to add that to hundreds of fact tables.

idesignpixels commented 2 years ago

Did the same in the end

adriexnet commented 1 year ago

Hi @rikinsk any news about the case insensitive option? it will be really useful

ian-emsens-shd commented 5 months ago

Any update on this? 👀