我有一个PostgreSQL数据库,其中包含带有单独记录的表test_table
。第一列是简单的store_id
,第二列meausurement
是嵌套的json。
store_id | measurement
----------------------
0 | {...}
measurement
列的格式如下:
{
'file_info': 'xxxx',
'data': {
'contour_data': {
'X': [-97.0, -97.0, -97.0, -97.0, -97.0, -97.0],
'Y': [-43.0, -41.0, -39.0, -39.0, -38.0, -36.0]
}
}
}
我想在Tableau中的散点图中绘制Y
与X
。因此,我将数据库成功连接到Tableau的PostgreSQL连接器。从this页面中,我了解到,由于Tableau不直接支持Postgres的json
数据类型,因此我必须使用自定义SQL查询从json对象提取数据。我已经在Tableau中尝试了以下自定义SQL查询:
select
store_id as store_id,
measurement#>>'{data, contour_data, X}' as contour_points_x,
measurement#>>'{data, contour_data, Y}' as contour_points_y
from test_table
将两个数组成功提取到两个新列contour_points_x
和contour_points_y
。但是,两个新列都在string
类型的Tableau中,因此我不能将它们用作绘图的数据源。
我必须如何调整自定义SQL查询以使Tableau散点图中的数据数组可绘制?
看起来您需要拆分列。检查此https://help.tableau.com/current/pro/desktop/en-us/split.htm
编辑-当您可以可靠地假设每个列表中点数的上限时,链接方法有效。 https://apogeeintegration.com/blog/apogee-busts-out-multi-value-cells-using-tableau-prep-builder
这里描述了一种分割任意大小列表的方法。