提问人: 提问时间:3/24/2023 最后编辑:philipxy 更新时间:3/24/2023 访问量:68
如何在postgres sql中规范化table1?
How to normalize table1 in postgres sql?
问:
我需要通过拆分“error occurred at”列来规范化 table1(以技术方式),使其类似于 table2 中所示。
是否有任何 DML 功能可以帮助我解决这个问题?因此,在不使用超前滞后功能的情况下传输了其余信息?
我尝试使用string_to_array和转置函数。
答:
0赞
Sannat Bhasin
3/24/2023
#1
WITH split_dates AS (
SELECT other_columns..., unnest(string_to_array(error_occured_at, ', '))::date AS date
FROM table1
WHERE error_occured_at RLIKE "," -- Only considering rows that actually do contain a comma
)
INSERT INTO table1 (other_columns..., error_occured_at)
SELECT other_columns..., date
FROM split_dates;
如果要删除旧格式的行,可以执行以下操作:error_occured_at
DELETE FROM table1
WHERE error_occured_at RLIKE ","
0赞
SelVazi
3/24/2023
#2
您可以通过结合以下内容来做到这一点:unnest
string_to_array
SELECT store_name, subject_of_collection, cost, checkpoint, errors_found, s. error_occured_at
FROM table1, unnest(string_to_array(error_occured_at, ', ')) as s(error_occured_at)
评论