41
41
class JSONSchemaToPostgres (JSONSchemaToSQL ):
42
42
"""Convert JSON Schema types to Postgres types."""
43
43
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 :
45
50
"""Initialize the JSONSchemaToPostgres instance."""
46
- super ().__init__ ()
51
+ super ().__init__ (* args , ** kwargs )
47
52
self .content_encoding = content_encoding
48
53
49
54
def handle_raw_string (self , schema ):
@@ -63,6 +68,10 @@ class PostgresConnector(SQLConnector):
63
68
allow_merge_upsert : bool = True # Whether MERGE UPSERT is supported.
64
69
allow_temp_tables : bool = True # Whether temp tables are supported.
65
70
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
+
66
75
def __init__ (self , config : dict ) -> None :
67
76
"""Initialize a connector to a Postgres database.
68
77
@@ -267,7 +276,10 @@ def _handle_array_type(self, jsonschema: dict) -> ARRAY | JSONB:
267
276
@cached_property
268
277
def jsonschema_to_sql (self ) -> JSONSchemaToSQL :
269
278
"""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
+ )
271
283
to_sql .fallback_type = TEXT
272
284
to_sql .register_type_handler ("integer" , BIGINT )
273
285
to_sql .register_type_handler ("object" , JSONB )
0 commit comments