@@ -208,6 +208,7 @@ def do_connect(
208
208
database : str | None = None ,
209
209
schema : str | None = None ,
210
210
autocommit : bool = True ,
211
+ enable_map_support : bool = True ,
211
212
** kwargs : Any ,
212
213
) -> None :
213
214
"""Create an Ibis client connected to PostgreSQL database.
@@ -228,6 +229,9 @@ def do_connect(
228
229
PostgreSQL schema to use. If `None`, use the default `search_path`.
229
230
autocommit
230
231
Whether or not to autocommit
232
+ enable_map_support
233
+ Whether or not to enable map support. If `True`, the HSTORE
234
+ extension will be loaded to support maps of string -> string.
231
235
kwargs
232
236
Additional keyword arguments to pass to the backend client connection.
233
237
@@ -278,7 +282,7 @@ def do_connect(
278
282
279
283
self .con .adapters .register_dumper (type (pd .NaT ), NatDumper )
280
284
281
- self ._post_connect ()
285
+ self ._post_connect (enable_map_support )
282
286
283
287
@util .experimental
284
288
@classmethod
@@ -296,19 +300,20 @@ def from_connection(cls, con: psycopg.Connection, /) -> Backend:
296
300
new_backend ._post_connect ()
297
301
return new_backend
298
302
299
- def _post_connect (self ) -> None :
303
+ def _post_connect (self , enable_map_support : bool = True ) -> None :
300
304
import psycopg .types
301
305
import psycopg .types .hstore
302
306
303
307
con = self .con
304
308
305
309
try :
306
310
# try to load hstore
307
- with con .cursor () as cursor , con .transaction ():
308
- cursor .execute ("CREATE EXTENSION IF NOT EXISTS hstore" )
309
- psycopg .types .hstore .register_hstore (
310
- psycopg .types .TypeInfo .fetch (self .con , "hstore" ), self .con
311
- )
311
+ if enable_map_support :
312
+ with con .cursor () as cursor , con .transaction ():
313
+ cursor .execute ("CREATE EXTENSION IF NOT EXISTS hstore" )
314
+ psycopg .types .hstore .register_hstore (
315
+ psycopg .types .TypeInfo .fetch (self .con , "hstore" ), self .con
316
+ )
312
317
except psycopg .Error as e :
313
318
warnings .warn (f"Failed to load hstore extension: { e } " )
314
319
except TypeError :
0 commit comments