Postgresql 在红移表中存储数组的正确方法是什么?

Postgresql 在红移表中存储数组的正确方法是什么?,postgresql,apache-spark,dataframe,apache-spark-sql,amazon-redshift,Postgresql,Apache Spark,Dataframe,Apache Spark Sql,Amazon Redshift,在红移中创建表时,我遇到以下错误: Column "main.sales_metrics" has unsupported type "character varying[]".; 在DataFrame架构中,它如下所示: |-- sales_metrics: array (nullable = true) |-- element: string (nullable = true) 我试图像在PostgreSQL中通常那样声明该列:sales\u metrics text[]正如我

在红移中创建表时,我遇到以下错误:

Column "main.sales_metrics" has unsupported type "character varying[]".;
在DataFrame架构中,它如下所示:

|-- sales_metrics: array (nullable = true)
     |-- element: string (nullable = true)
我试图像在PostgreSQL中通常那样声明该列:
sales\u metrics text[]
正如我从文档中读到的,Amazon Redshift不支持PostgreSQL数据类型

那么,在RedShift中创建表时,我应该如何正确声明存储
数组[String]
sales\u metrics
列呢?

,但是有一些是可以使用的。 基本上,您可以将数据存储为varchar,并使用json函数查询数据

例如:

create temporary table sales_metrics (col1 varchar(20));
insert into sales_metrics values ('[1,2,3]');
然后


除了@ittus的答案之外,请注意Redshift对数组的存储方式非常挑剔

         json_arrays          | is_valid_json_array
------------------------------+---------------------
 []                           | t
 ["a","b"]                    | t
 ["a",["b",1,["c",2,3,null]]] | t
 {"a":1}                      | f
 a                            | f
 {foo, bar}                   | f
 {"one", "two"}               | f
 [x,y,z]                      | f
 [1,2,]                       | f
         json_arrays          | is_valid_json_array
------------------------------+---------------------
 []                           | t
 ["a","b"]                    | t
 ["a",["b",1,["c",2,3,null]]] | t
 {"a":1}                      | f
 a                            | f
 {foo, bar}                   | f
 {"one", "two"}               | f
 [x,y,z]                      | f
 [1,2,]                       | f