Skip to content

Commit 445ad88

Browse files
committed
fix: support postgresql array types
1 parent 635f6d5 commit 445ad88

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

awswrangler/_data_types.py

+2
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ def pyarrow2postgresql( # noqa: PLR0911
213213
return pyarrow2postgresql(dtype=dtype.value_type, string_type=string_type)
214214
if pa.types.is_binary(dtype):
215215
return "BYTEA"
216+
if pa.types.is_list(dtype):
217+
return pyarrow2postgresql(dtype=dtype.value_type, string_type=string_type) + "[]"
216218
raise exceptions.UnsupportedType(f"Unsupported PostgreSQL type: {dtype}")
217219

218220

awswrangler/_databases.py

+2
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,8 @@ def generate_placeholder_parameter_pairs(
359359
"""Extract Placeholder and Parameter pairs."""
360360

361361
def convert_value_to_native_python_type(value: Any) -> Any:
362+
if isinstance(value, list):
363+
return value
362364
if pd.isna(value):
363365
return None
364366
if hasattr(value, "to_pydatetime"):

tests/unit/test_postgresql.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ def test_unknown_overwrite_method_error(postgresql_table, postgresql_con):
100100
def test_sql_types(postgresql_table, postgresql_con):
101101
table = postgresql_table
102102
df = get_df()
103+
df["arrint"] = pd.Series([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
104+
df["arrstr"] = pd.Series([["a", "b", "c"], ["d", "e", "f"], ["g", "h", "i"]])
103105
df.drop(["binary"], axis=1, inplace=True)
104106
wr.postgresql.to_sql(
105107
df=df,
@@ -108,7 +110,7 @@ def test_sql_types(postgresql_table, postgresql_con):
108110
schema="public",
109111
mode="overwrite",
110112
index=True,
111-
dtype={"iint32": "INTEGER"},
113+
dtype={"iint32": "INTEGER", "arrint": "INTEGER[]", "arrstr": "VARCHAR[]"},
112114
)
113115
df = wr.postgresql.read_sql_query(f"SELECT * FROM public.{table}", postgresql_con)
114116
ensure_data_types(df, has_list=False)
@@ -130,6 +132,8 @@ def test_sql_types(postgresql_table, postgresql_con):
130132
"timestamp": pa.timestamp(unit="ns"),
131133
"binary": pa.binary(),
132134
"category": pa.float64(),
135+
"arrint": pa.list_(pa.int64()),
136+
"arrstr": pa.list_(pa.string()),
133137
},
134138
)
135139
for df in dfs:

0 commit comments

Comments
 (0)