PostgreSQL-与string_agg相反
问题描述:
我正在寻找一个与 string_agg
相反的postgresql函数。
I'm looking for a postgresql function that will do the opposite of string_agg
.
我有一个电影表,其中的tag列包含诸如
I have a movies table where the tags column contains values such as
Action|Adventure|Drama|Horror|Sci-Fi
Action|Horror|Sci-Fi
我想从此列中获得不同的标签列表,例如
I would like to get a distinct list of tags from this column, for example
Action
Adventure
Drama
Horror
Sci-Fi
答
您可以使用 unnest()
和 string_to_array()
:
select unnest(string_to_array(t.col, ','))
from t