Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 979
Erald Totraku Avatar asked Oct 21 '25 08:10

Erald Totraku


1 Answers

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`
    }
  }
})
like image 50
Pavel Tiunov Avatar answered Oct 27 '25 04:10

Pavel Tiunov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!