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

Add support for sorting by json path

Open cortexin opened this issue 6 years ago • 17 comments

It would be nice to have the ability to sort the query results by a path of a JSON columns For example, for a table like

CREATE TABLE products (
  id serial NOT NULL PRIMARY KEY,
  translated_name jsonb NULL
);

I would like to have the ability to do something like

query productsSortedByName {
    products(order_by: {translated_name: {path: "en", how: asc_nulls_last}}) {
       id
       name: translated_name (path: "en")
   }
}

cortexin avatar Jul 25 '19 09:07 cortexin

I second this request

kmclaugh avatar Jan 28 '20 03:01 kmclaugh

At the very least, we should be able to sort by a named path

so for a data jsonb column like this data: { "amount": 10 } and a query like this sometable { timestamp data amount: data(path: "amount") } You could sort by this "orderBy": [{"amount": "asc"}]

kmclaugh avatar Jan 28 '20 03:01 kmclaugh

Any updates on this by chance? Currently this feature is the only thing missing in order to make the jump :(

jordan-lumley avatar Sep 02 '20 02:09 jordan-lumley

I also vote for this feature. Thank you!

alexandrim0 avatar Sep 17 '20 16:09 alexandrim0

This feature is highly anticipated by our team, thank you.

Rangot avatar Sep 18 '20 12:09 Rangot

Vote for this. Today we have to sort data (by translatable fields) on the client side.

akelix avatar Sep 21 '20 08:09 akelix

Vote+1 this feature

hscstudio avatar Jan 22 '21 01:01 hscstudio

+1

lapidus avatar May 08 '21 13:05 lapidus

+1

lakhansamani avatar Jun 11 '21 05:06 lakhansamani

+1

lakhansamani avatar Jul 05 '21 22:07 lakhansamani

+1

anthonyra avatar Sep 21 '21 18:09 anthonyra

+1

pi-benoit avatar Mar 15 '22 14:03 pi-benoit

+1

jxwang2010 avatar Mar 22 '22 03:03 jxwang2010

+1

tlebeitsuk avatar Apr 04 '22 06:04 tlebeitsuk

+1

mikejackowski avatar Apr 05 '22 22:04 mikejackowski

+1

andrewcbuensalida avatar Apr 26 '22 14:04 andrewcbuensalida

+1

jflambert avatar Jul 28 '22 20:07 jflambert

We also need this feature.

jaycverg avatar Aug 16 '22 11:08 jaycverg

Another plus one for this feature request.

I have a different use case though

I have object like this:

Person 0..1 -> 0..* Attributes(name, value)

Attribute is a simple label / value table, such as weight:65 pulse:86 etc.

I want to be able to order Person, where an attribute has a given name, so I can sort people by their weight, or heart rate.

A syntax might look something like:

Person.... order_by: { Attribute:{ name:{_eq: "weight"}, sort_value:{ value :asc}} }

cn-icore avatar Sep 25 '22 12:09 cn-icore

Hey folks. As a little sneak preview: Native Queries will be out of beta and available in Hasura CE for PostgreSQL with the release of v2.28, which is imminent. Native Queries allow you to express your query as arbitrary SQL, while still getting all of the usual Hasura goodness.

While this isn't quite as trivial as being able to order by a computation, you might find it useful. You'd add your expected query:

SELECT id, translated_name -> "en" AS name
FROM products
ORDER BY translated_name -> "en" ASC NULLS LAST

Give it a name, then you can use Hasura to select as usual.

SamirTalwar avatar Jun 20 '23 09:06 SamirTalwar

care to link to a PR# @manasag ?

jflambert avatar Nov 23 '23 15:11 jflambert

Hi @jflambert, this issue is currently solved using Native Queries feature, as mentioned by Samir in the earlier comment. More direct support for this is not planned for current V2 of Hasura. We will revisit support for this in V3. I have created a new issue to track for V3 support #10018

manasag avatar Nov 28 '23 05:11 manasag