如何应对Redshift缺乏对阵列的支持

Bes*_*ces 7 amazon-web-services amazon-redshift

Redshift不支持Arrays,但是我的源数据库在Redshift中有几个我需要的Array列.

尝试将其迁移到Redshift时,应如何处理此字段类型?

moe*_*tel 10

虽然Redshift不支持PostgreSQL意义上的数组,但它提供了一些您可能需要查看的JSON函数:http://docs.aws.amazon.com/redshift/latest/dg/json-functions.html

您可以将数组插入varchar列:

create temporary table _test (col1 varchar(20));
insert into _test values ('[1,2,3]');
Run Code Online (Sandbox Code Playgroud)

然后使用json_extract_array_element_text()将产生:

db=# select json_extract_array_element_text(col1, 2) from _test;
 json_extract_array_element_text
---------------------------------
 3
(1 row)
Run Code Online (Sandbox Code Playgroud)