尝试在 Postgres 中将包含时间戳数组的列拆分为分隔文本字符串时出现"Function does not exist"错误



我有一个表格,其中包含我想要转换为字符串的数组的列,以便我可以通过定界符将它们拆分为多列。

我在与时区的日期阵列中遇到困难。

create materialized view matview1 as select
    (location) as location,
    (nullif(split_part(string_agg(distinct name,'; '),'; ',1),'')) as name1,
    (nullif(split_part(string_agg(distinct name,'; '),'; ',2),'')) as name2,
    (nullif(split_part(string_agg(distinct name,'; '),'; ',3),'')) as name3,
    (array_agg(distinct(event_date_with_timestamp))) as event_dates
    from table2 b
    group by location;

在上面的代码中,我正在创建一个表面的视图,以将与某些位置相关的所有表条目合并为单行。

如何像使用名称一样(例如"名称"数组中的名称(例如name1,name2和name3),如何为每个event_date条目创建其他列。

我尝试使用以下方式将数组更改为字符串格式

(nullif(split_part(array_to_string(array_agg(distinct(event_date_with_timestamp))),'; ',1),'')) as event_date1

但这引发了错误:

"函数array_to_string(timestamp with time Zone [])不存在"

铸造到不同的数据类型总是会产生错误,说我不能从类型的时间戳施放到其他任何东西中。

我找到了一种通过从时间戳记到文本然后再返回的方法来完成此操作:

(nullif(split_part(string_agg(distinct event_date::text,'; '),'; ',1),'')::date) as date1,

最新更新