English 中文(简体)
JSONB数据类型,后遗字
原标题:Order by JSONB data type with sequelize literal

目前使用这一结构来询问所有项目:

const filteredItems = await allItems.findAll({
         where: conditions,
         include: associations,
         order: sortingCriteria,
         limit: limit,
         offset: offset,
      });

The sortingCriteria currently has this structure:

const sortingCriteria = [
      ["price", "ASC NULLS LAST"],
      ["created_at", "DESC NULLS LAST"],
    ]

∗∗∗∗ <代码>所有项目表。 在同一张表格中,还有另一个领域,即<代码>details,有

此外,我需要补充一种分类标准,因此,我用在JSONB中的一些具体数据来排列,这一结构是:

details = { 
            "sizes": {
               "height": 10,
               "width": 20,
            },
            "capacities": {
               "volume": 200,
               "weight": 2,
            }
          }

Let s say I want to order by volume all the items (and also by price and created_at, as I already have). How should I include that in sortingCriteria ?

使用JSONB而不是设置表格和JOIN是个原因。 我已经尝试过,而且每张桌上就座,业绩大大提高。 用于主食目的,请见<条码> 限值/代码>和<条码>。 I m

问题回答

关于<编码>条码,请参见<条码>。 使用<代码>->>的操作者。

order: [
  [sequelize.literal( details->> capacities ->> volume  ),  ASC ]
]

希望会有助于





相关问题
摘录数据

我如何将Excel板的数据输入我的Django应用? I m将PosgreSQL数据库作为数据库。

Postgres dump of only parts of tables for a dev snapshot

On production our database is a few hundred gigabytes in size. For development and testing, we need to create snapshots of this database that are functionally equivalent, but which are only 10 or 20 ...

How to join attributes in sql select statement?

I want to join few attributes in select statement as one for example select id, (name + + surname + + age) as info from users this doesn t work, how to do it? I m using postgreSQL.

What text encoding to use?

I need to setup my PostgreSQL DB s text encoding to handle non-American English characters that you d find showing up in languages such as German, Spanish, and French. What character encoding should ...

SQL LIKE condition to check for integer?

I am using a set of SQL LIKE conditions to go through the alphabet and list all items beginning with the appropriate letter, e.g. to get all books where the title starts with the letter "A": SELECT * ...

热门标签