Skip to content

Commit 99a7490

Browse files
Merge branch 'main' into edgarrmondragon/chore/refactors-typos-cleanup
2 parents f0986b6 + a93a12b commit 99a7490

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

target_postgres/connector.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ def prepare_table( # type: ignore[override] # noqa: PLR0913
144144
column_object = None
145145
if property_name in columns:
146146
column_object = columns[property_name]
147+
147148
self.prepare_column(
148149
full_table_name=table.fullname,
149150
column_name=property_name,
@@ -246,6 +247,14 @@ def to_sql_type(self, jsonschema_type: dict) -> sa.types.TypeEngine: # type: ig
246247
json_type_dict["format"] = jsonschema_type["format"]
247248
if encoding := jsonschema_type.get("contentEncoding", False):
248249
json_type_dict["contentEncoding"] = encoding
250+
# Figure out array type, but only if there's a single type
251+
# (no array union types)
252+
if (
253+
"items" in jsonschema_type
254+
and "type" in jsonschema_type["items"]
255+
and isinstance(jsonschema_type["items"]["type"], str)
256+
):
257+
json_type_dict["items"] = jsonschema_type["items"]["type"]
249258
json_type_array.append(json_type_dict)
250259
else:
251260
msg = "Invalid format for jsonschema type: not str or list."
@@ -282,7 +291,13 @@ def pick_individual_type(self, jsonschema_type: dict): # noqa: PLR0911
282291
if "object" in jsonschema_type["type"]:
283292
return JSONB()
284293
if "array" in jsonschema_type["type"]:
285-
return ARRAY(JSONB())
294+
items_type = jsonschema_type.get("items")
295+
if "string" == items_type:
296+
return ARRAY(TEXT())
297+
if "integer" == items_type:
298+
return ARRAY(BIGINT())
299+
else:
300+
return ARRAY(JSONB())
286301

287302
# string formats
288303
if jsonschema_type.get("format") == "date-time":

0 commit comments

Comments
 (0)