如何使用Presto在字符串列中获取第一个元组
因此,我在表中有一个列,该列的数据类型是VARCHAR,但其中包含一组元组,因此我需要提取表中的阵列的第一个元组,
这是原始表
用户ID | 注释。 |
---|---|
1 | [[“ Hello World”,1],[“您如何”,1],[这是一个“一个”,1]] |
2 | [[“ Hello”,1],[How''how'',1],, [“ this”,1]] |
这就是我正在寻找的东西,请注意,'评论'列的数据类型是 varchar 。
用户ID | 评论 |
---|---|
1 | Hello World |
2 | Hello |
so i am having a column in the table, the data type of the column is varchar, but it contains an array of tuples, so what I need is to extract the first tuple of the array in the table
this is the original table
userid | comments |
---|---|
1 | [["hello world",1],["How did you",1],[" this is the one",1]] |
2 | [["hello ",1],["How ",1],[" this",1]] |
and this is what i am looking for , please notice that the datatype of 'comments' column is varchar.
userid | comments |
---|---|
1 | hello world |
2 | hello |
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
:
请注意,如果您需要多个值,则只需提取单个值(类似于完成的一个在这里但是使用数组,例如
array(json)
)。json_extract_scalar
should do the trick:Output:
Note that it will allow to extract only single value, if you want multiple values you will need to do some casting (similar to one done here but using arrays, for example
array(json)
).