gpt4 book ai didi

how to order by multiple columns in supabase?(如何在上库中按多列排序?)

转载 作者:bug小助手 更新时间:2023-10-25 13:44:48 25 4
gpt4 key购买 nike



How can I order by publication, then by title in supabase?

我怎么才能先按出版物排序,再按标题排序呢?


This is wrong:

这是错误的:



.order('publicationDate', { ascending: false }, 'title', { ascending: true });


If I make them separate lines, the 2nd one overrides the first.

如果我将它们分开,第二行将覆盖第一行。


更多回答

Reverse the order. First line supa; last line pub. Assuming enough have same title and pub...

颠倒顺序。第一排酒吧;最后一排酒吧。假设有足够多的人有相同的标题和酒吧。

what do you mean? the columns I'm trying to use in the order section are date and title.

你是什么意思?我在Order部分尝试使用的列是Date和TITLE。

Sorry two things, not 3, so just do it in separate lines. First line:do it by title. Second line: do it by date. Why it might work: when it reorders by date, there's no reason to re-order items that have the same date so it may preserve the title ordering for items that have same date.

对不起是两件事,不是三件事,所以分开做就行了。第一行:按标题来做。第二行:按日期完成。可行理由:当它按日期重新排序时,没有理由重新排序具有相同日期的项目,这样它就可以保留具有相同日期的项目的标题顺序。

ive already tried two separate .order lines. it doesnt work.

我已经尝试了两个单独的.Order行。这不管用。

sorry Abel - you are right. it does work. i don't know why it didnt on the previous attempt. For others, two separate .order lines will order in two cascading flows. I apologise to you Abel. thank you.

对不起,亚伯--你说得对。它确实起作用了。我不知道为什么它没有在前一次尝试。对于其他订单,两个单独的.Order行将在两个级联流中进行排序。我向你道歉,亚伯。谢谢。

优秀答案推荐

According to the comment in the source code of @supabase/postgres-js package
the only way to order by multiple columns is by using .order method multiple times.

根据@supabase/postgres-js包源代码中的注释,按多列排序的唯一方法是多次使用.order方法。



I sort of just wrote this without testing it, so it might not work (syntax), but let me know what happens!

我只是在没有测试的情况下编写了这段代码,所以它可能无法工作(语法),但请让我知道会发生什么!


Some Context:

一些背景信息:


In Supabase, which uses PostgREST behind the scenes, when you want to order by multiple columns, you should use an array.

在后台使用PostgREST的Supabase中,当您想要按多列排序时,您应该使用数组。


The .order() function enables users to order by multiple columns by supplying an array of columns and, optionally, an array of corresponding ordering directions.

.order()函数使用户能够通过提供列数组和相应排序方向数组(可选)来按多列排序。


Now the code:

现在代码如下:


.order([{ column: 'publicationDate', order: 'desc' }, { column: 'title', order: 'asc' }])

So, your full Supabase query might look something like this:

因此,完整的Supabase查询可能如下所示:


supabase
.from('yourTableName')
.select('*')
.order([{ column: 'publicationDate', order: 'desc' }, { column: 'title', order: 'asc' }])


.order([{ column: 'publicationDate', ascending: false }, { column: 'title', ascending: true }])

This code will first order your results by publicationDate in descending order (most recent first) and then, for items with the same publication date, it will further order them by title in ascending order (alphabetical order). This should give you the desired ordering for your Supabase results.

这段代码将首先按照publicationDate以降序(最近的在前)对结果进行排序,然后,对于具有相同发布日期的项目,它将进一步按照标题以升序(字母顺序)进行排序。这将为您的Supplement结果提供所需的排序。


更多回答

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com