如何处理 cube.js 中 postgres 数据库中的 jsonb 对象?
How to deal with jsonb objects in postgres databases in cube.js?
我有一个带有 jsonb 列的 postgres 数据库,其中包含自定义属性键和值。有没有办法让这些显示在维度中?
您可以对 https://www.postgresql.org/docs/9.5/functions-json.html 使用 ->>
json 运算符。例如:
cube(`Users`, {
sql: `select * from users`,
// ...
dimensions: {
firstName: {
sql: `${CUBE}.attributes->>'firstName'`,
type: `string`
},
lastName: {
sql: `${CUBE}.attributes->>'lastName'`,
type: `string`
}
}
})
我有一个带有 jsonb 列的 postgres 数据库,其中包含自定义属性键和值。有没有办法让这些显示在维度中?
您可以对 https://www.postgresql.org/docs/9.5/functions-json.html 使用 ->>
json 运算符。例如:
cube(`Users`, {
sql: `select * from users`,
// ...
dimensions: {
firstName: {
sql: `${CUBE}.attributes->>'firstName'`,
type: `string`
},
lastName: {
sql: `${CUBE}.attributes->>'lastName'`,
type: `string`
}
}
})