【发布时间】:2020-09-05 18:04:46
【问题描述】:
给定 PostgreSQL 中的表 table1:
我想创建新表table2 喜欢:
所以新表将包括:
column_1 = old_column_1 + old_column_2 + 等于 (old_column_3 - old_column_2 的长度) 的数字“0”的串联 column_2 = old_column_1 + old_column_2 + 等于 (old_column_3 - old_column_2 的长度) 的数字“9”的串联当min_length 不等于max_length 时,我需要考虑所有可能的长度。所以对于 "42";"32";6;8 行,所有的长度都是:6,7 和 8。
我尝试创建新的 table2 AS table1,然后创建新列 start 和 stop,然后像这样连接列 1 和 2:
create table table2 as select * from table1;
alter table table2 add column start text,
add column stop text;
update table2 set start = number1 || number2
用于连接前 2 列。但我不知道如何进行所有连接,添加“0”和“9”。
【问题讨论】:
标签: sql postgresql concat generate-series set-returning-functions