在红移中对逗号分隔值
我的红移中有一个comma分离值的列/字段。
My_field |
---|
Apple,香蕉,糖果 |
糖果,香蕉 |
香蕉,苹果 |
和我想将它们变成
my_field_sorted |
---|
苹果,香蕉,糖果 |
香蕉,糖果 |
苹果,香蕉, |
有什么简单的方法可以使用本机SQL/Redshift Syntax做到这一点吗? 我必须求助于UDFS吗?
我没有创建UDFS的经验 - 有人有类似的UDF可以共享吗?
还是有人可以帮助将此功能变成UDF?
def sort_comma_sep_values(x):
if type(x) is str:
list_of_x = x.split(',')
list_of_x = list(dict.fromkeys(list_of_x))
list_of_x = sorted(list_of_x)
output = ','.join(list_of_x)
return output
else:
return None
I have a column/field in Redshift with comma separated values.
my_field |
---|
apple,banana,candy |
candy,banana |
banana,apple |
And I want to turn these into
my_field_sorted |
---|
apple,banana,candy |
banana,candy |
apple,banana |
Is there an easy way to do this with native SQL/Redshift syntax?
Do I have to resort to UDFs?
I don't have any experience creating UDFs - does anyone have a similar UDFs that they can share?
Or can someone help turn this function into an UDF?
def sort_comma_sep_values(x):
if type(x) is str:
list_of_x = x.split(',')
list_of_x = list(dict.fromkeys(list_of_x))
list_of_x = sorted(list_of_x)
output = ','.join(list_of_x)
return output
else:
return None
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论