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

Ordering JSON column not working #131

Closed
kiwicopple opened this issue Nov 12, 2020 · 5 comments · Fixed by #132
Closed

Ordering JSON column not working #131

kiwicopple opened this issue Nov 12, 2020 · 5 comments · Fixed by #132
Labels
bug Something isn't working released

Comments

@kiwicopple
Copy link
Member

Bug report

Describe the bug

This is failing

const { data: products, error } = await supabase
        .from('products')
        .select('*')
        .order('metadata->index'

Caused by this:

`"${column}".${ascending ? 'asc' : 'desc'}.${nullsFirst ? 'nullsfirst' : 'nullslast'}`

If we remove the quotes from the "${column}" then it works.

@kiwicopple kiwicopple added the bug Something isn't working label Nov 12, 2020
@kiwicopple
Copy link
Member Author

kiwicopple commented Nov 12, 2020

@soedirgo - just need to get an understanding of the "${column}". Is there a requirement for it to be wrapped in quotes?

Perhaps we can just encodeURIComponent(${column})?

@thorwebdev
Copy link
Member

To give an example, this is my supabase-js query:

const { data: products, error } = await supabase
        .from('products')
        .select('*, prices(*)')
        .eq('active', true)
        .order('metadata->index')
        .order('unit_amount', { foreignTable: 'prices' });

This is what postgrest-js currently generates:

https://jhomlobmvyuadfdnpnkb.supabase.co/rest/v1/products?select=*%2Cprices%28*%29&active=eq.true&order=%22metadata-%3Eindex%22.asc.nullslast&%22prices%22.order=%22unit_amount%22.asc.nullslast&apikey=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiYW5vbiIsImlhdCI6MTYwNTA3MTUwNSwiZXhwIjoxOTIwNjQ3NTA1fQ.FZJkLOldXfPWN7Gtq7J4zFIh5cmnzSzBh_U3Jb0fjhY

Which errors with

{
  "hint": null,
  "details": null,
  "code": "42703", 
  "message": "column products.metadata->index does not exist"
}

when I remove the quotes from all order parts it works:

https://jhomlobmvyuadfdnpnkb.supabase.co/rest/v1/products?select=*%2Cprices%28*%29&active=eq.true&order=metadata-%3Eindex.asc.nullslast&%22prices%22.order=unit_amount.asc.nullslast&apikey=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiYW5vbiIsImlhdCI6MTYwNTA3MTUwNSwiZXhwIjoxOTIwNjQ3NTA1fQ.FZJkLOldXfPWN7Gtq7J4zFIh5cmnzSzBh_U3Jb0fjhY

@soedirgo
Copy link
Member

Is there a requirement for it to be wrapped in quotes?

This was to anticipate column names like player.name which you'd need to wrap in quotes, but breaking JSONB columns makes this a nonstarter. Will push a fix soon 👍.

@soedirgo
Copy link
Member

soedirgo commented Nov 12, 2020

Also, I don't think postgrest-js supports ordering on multiple columns, doing multiple orders will ignore the previous ones. Will try to make this work as well.

Just realized you were doing the second order on a foreign table, which should still work. Will put off multiple order columns for now...

@github-actions
Copy link

🎉 This issue has been resolved in version 0.21.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

soedirgo added a commit that referenced this issue Feb 13, 2021
Automatically quoting tables/columns led to many unintended problems:
\#131, \#149. This removes all remaining quoting of names.
soedirgo added a commit that referenced this issue Feb 13, 2021
Automatically quoting tables/columns led to many unintended problems: #131, #149. This removes all remaining quoting of names.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants