Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Consider max VARCHAR length of 10,485,760 #499

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions target_postgres/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,14 @@
class JSONSchemaToPostgres(JSONSchemaToSQL):
"""Convert JSON Schema types to Postgres types."""

def __init__(self, *, content_encoding: bool = True) -> None:
def __init__(
self,
*args: t.Any,
content_encoding: bool = True,
**kwargs: t.Any,
) -> None:
"""Initialize the JSONSchemaToPostgres instance."""
super().__init__()
super().__init__(*args, **kwargs)
self.content_encoding = content_encoding

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

#: Maximum length of a VARCHAR column.
#: https://www.postgresql.org/docs/current/datatype-character.html
max_varchar_length: int | None = 10_485_760

def __init__(self, config: dict) -> None:
"""Initialize a connector to a Postgres database.

Expand Down Expand Up @@ -267,7 +276,10 @@ def _handle_array_type(self, jsonschema: dict) -> ARRAY | JSONB:
@cached_property
def jsonschema_to_sql(self) -> JSONSchemaToSQL:
"""Return a JSONSchemaToSQL instance with custom type handling."""
to_sql = JSONSchemaToPostgres(content_encoding=self.interpret_content_encoding)
to_sql = JSONSchemaToPostgres(
content_encoding=self.interpret_content_encoding,
max_varchar_length=self.max_varchar_length,
)
to_sql.fallback_type = TEXT
to_sql.register_type_handler("integer", BIGINT)
to_sql.register_type_handler("object", JSONB)
Expand Down
Loading