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

order by with multiple aggregate fields throws error #2981

Closed
ardsh opened this issue Oct 2, 2019 · 4 comments · Fixed by #2998
Closed

order by with multiple aggregate fields throws error #2981

ardsh opened this issue Oct 2, 2019 · 4 comments · Fixed by #2998
Assignees
Labels
c/server Related to server e/quickfix can be wrapped up in few hours k/bug Something isn't working p/high candidate for being included in the upcoming sprint

Comments

@ardsh
Copy link

ardsh commented Oct 2, 2019

Making a query with 2 aggregate fields in order_by that use min/max and different relations causes an SQL error.

{
  author (order_by: [{
    articles_aggregate: {
        min: {
            title: asc
        }
    }
  }, {
    posts_aggregate: {
        max: {
           text: asc
        }
    }
  }]) {
    id
    name
    articles {
        id
    }
  }
@shahidhk
Copy link
Member

shahidhk commented Oct 2, 2019

@ardsh What is the SQL error?

@ardsh
Copy link
Author

ardsh commented Oct 2, 2019

{
  "errors": [
    {
      "extensions": {
        "internal": {
          "statement": "SELECT  coalesce(json_agg(\"root\" ORDER BY \"root.ar.root.order_by.max.date\" ASC NULLS LAST, \"root.ar.root.order_by.min.text\" DESC NULLS FIRST), '[]' ) AS \"root\" FROM  (SELECT  \"_3_root.ar.root.order_by\".\"max.date\" AS \"root.ar.root.order_by.max.date\", \"_3_root.ar.root.order_by\".\"min.text\" AS \"root.ar.root.order_by.min.text\", row_to_json((SELECT  \"_4_e\"  FROM  (SELECT  \"_0_root.base\".\"id\" AS \"id\"       ) AS \"_4_e\"      ) ) AS \"root\" FROM  (SELECT  *  FROM \"public\".\"user\"  WHERE ('true')     ) AS \"_0_root.base\" LEFT OUTER JOIN LATERAL (SELECT  min(\"text\" ) AS \"min.text\", max(\"date\" ) AS \"max.date\" FROM  (SELECT  \"_1_root.ar.root.order_by.base\".\"text\" AS \"text\", \"_1_root.ar.root.order_by.base\".\"date\" AS \"date\", 1 AS \"root.ar.root.order_by__one\" FROM  (SELECT  *  FROM \"public\".\"tasks\"  WHERE ((\"_0_root.base\".\"id\") = (\"user_id\"))     ) AS \"_1_root.ar.root.order_by.base\"      ) AS \"_2_root.ar.root.order_by\"      ) AS \"_3_root.ar.root.order_by\" ON ('true')    ORDER BY \"root.ar.root.order_by.max.date\" ASC NULLS LAST, \"root.ar.root.order_by.min.text\" DESC NULLS FIRST  ) AS \"_5_root\"      ",
          "prepared": true,
          "error": {
            "exec_status": "FatalError",
            "hint": null,
            "message": "column _1_root.ar.root.order_by.base.date does not exist",
            "status_code": "42703",
            "description": null
          },
          "arguments": [
            "(Oid 114,Just (\"{\\\"x-hasura-role\\\":\\\"admin\\\"}\",Binary))"
          ]
        },
        "path": "$",
        "code": "unexpected"
      },
      "message": "postgres query error"
    }
  ]
}

This is with a slightly different query I executed

{
  user(order_by:[{
    notes_aggregate:{
      max:{
        date:asc
      }
    }
  }, {
    tasks_aggregate:{
      min:{
        text:desc
      }
    }
  }]) {
    id
  }
}

@0x777 0x777 added k/bug Something isn't working p/high candidate for being included in the upcoming sprint labels Oct 2, 2019
@0x777 0x777 added the c/server Related to server label Oct 2, 2019
rakeshkky added a commit to rakeshkky/graphql-engine that referenced this issue Oct 3, 2019
@rakeshkky
Copy link
Member

@ardsh Thanks for reporting the bug. Please find the fix in #2998.
It'd be highly helpful if you try out the preview app https://hge-ci-pull-2998.herokuapp.com/ and confirm the fix 🙂

@rakeshkky rakeshkky added the e/quickfix can be wrapped up in few hours label Oct 3, 2019
@ardsh
Copy link
Author

ardsh commented Oct 3, 2019

That seems to be working well, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c/server Related to server e/quickfix can be wrapped up in few hours k/bug Something isn't working p/high candidate for being included in the upcoming sprint
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants