Skip to content

Commit bdbb44c

Browse files
fix: Consider max VARCHAR length of 10,485,760 (#499)
1 parent c02fdb9 commit bdbb44c

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

target_postgres/connector.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,14 @@
4141
class JSONSchemaToPostgres(JSONSchemaToSQL):
4242
"""Convert JSON Schema types to Postgres types."""
4343

44-
def __init__(self, *, content_encoding: bool = True) -> None:
44+
def __init__(
45+
self,
46+
*args: t.Any,
47+
content_encoding: bool = True,
48+
**kwargs: t.Any,
49+
) -> None:
4550
"""Initialize the JSONSchemaToPostgres instance."""
46-
super().__init__()
51+
super().__init__(*args, **kwargs)
4752
self.content_encoding = content_encoding
4853

4954
def handle_raw_string(self, schema):
@@ -63,6 +68,10 @@ class PostgresConnector(SQLConnector):
6368
allow_merge_upsert: bool = True # Whether MERGE UPSERT is supported.
6469
allow_temp_tables: bool = True # Whether temp tables are supported.
6570

71+
#: Maximum length of a VARCHAR column.
72+
#: https://www.postgresql.org/docs/current/datatype-character.html
73+
max_varchar_length: int | None = 10_485_760
74+
6675
def __init__(self, config: dict) -> None:
6776
"""Initialize a connector to a Postgres database.
6877
@@ -267,7 +276,10 @@ def _handle_array_type(self, jsonschema: dict) -> ARRAY | JSONB:
267276
@cached_property
268277
def jsonschema_to_sql(self) -> JSONSchemaToSQL:
269278
"""Return a JSONSchemaToSQL instance with custom type handling."""
270-
to_sql = JSONSchemaToPostgres(content_encoding=self.interpret_content_encoding)
279+
to_sql = JSONSchemaToPostgres(
280+
content_encoding=self.interpret_content_encoding,
281+
max_varchar_length=self.max_varchar_length,
282+
)
271283
to_sql.fallback_type = TEXT
272284
to_sql.register_type_handler("integer", BIGINT)
273285
to_sql.register_type_handler("object", JSONB)

0 commit comments

Comments
 (0)