简体   繁体   中英

How to deal with jsonb objects in postgres databases in cube.js?

I have postgres database with a jsonb column which contains custom attribute keys and values. Is there any approach to get these to show up in the dimensions?

You can use ->> json operator for that https://www.postgresql.org/docs/9.5/functions-json.html . For example:

cube(`Users`, {
  sql: `select * from users`,

  // ...

  dimensions: {
    firstName: {
      sql: `${CUBE}.attributes->>'firstName'`,
      type: `string`
    },

    lastName: {
      sql: `${CUBE}.attributes->>'lastName'`,
      type: `string`
    }
  }
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM