graphql-engine icon indicating copy to clipboard operation
graphql-engine copied to clipboard

Case insensitive order_by

Open bertyhell opened this issue 5 years ago • 9 comments

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"
  },
]

bertyhell avatar Aug 11 '20 07:08 bertyhell

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

wwwdepot avatar Aug 18 '20 18:08 wwwdepot

@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?

nawgz avatar Sep 16 '21 23:09 nawgz

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

idesignpixels avatar Nov 10 '21 15:11 idesignpixels

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?

jflambert avatar Mar 24 '22 01:03 jflambert

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

bertyhell avatar Mar 24 '22 15:03 bertyhell

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

jflambert avatar Mar 24 '22 15:03 jflambert

Did the same in the end

idesignpixels avatar Mar 24 '22 16:03 idesignpixels

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

adriexnet avatar Mar 29 '23 08:03 adriexnet

Any update on this? 👀

ian-emsens-shd avatar Jun 05 '24 08:06 ian-emsens-shd