Redshift does not support Arrays, however my source database has several Array columns that I need in Redshift.
How should this field type be handled when trying to migrate it into Redshift?
Redshift does not support Arrays, however my source database has several Array columns that I need in Redshift.
How should this field type be handled when trying to migrate it into Redshift?
Surround it with a specific character that never appears on this field values.
Example:
And when querying it you just do this:
Also have in mind that
like
queries are expensive and can decrease your cluster's perfomance.To query array fields in a Redshift table you just need to JOIN your table with its array field.
EXAMPLE
Given a table of customers with relative orders as an array.
To select customer IDs and order ship dates for customers that have orders:
For each customer c that has orders, the FROM clause returns one row for each order o of the customer c. That row combines the customer row c and the order row o. Then the SELECT clause keeps only the c.id and o.shipdate. The result is the following.
Reference to: https://docs.aws.amazon.com/redshift/latest/dg/tutorial-query-nested-data-sqlextensions.html
While Redshift does not support arrays in the PostgreSQL-sense, it provides some JSON functions you might want to have a look at: http://docs.aws.amazon.com/redshift/latest/dg/json-functions.html
You can insert arrays into
varchar
columns:Then using
json_extract_array_element_text()
would yield: