Skip to content

Commit 35fc38b

Browse files
authored
feat(postgres): allow disablement of hstore extension loading (#11126)
Closes #11103.
1 parent 99be73b commit 35fc38b

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

ibis/backends/postgres/__init__.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ def do_connect(
208208
database: str | None = None,
209209
schema: str | None = None,
210210
autocommit: bool = True,
211+
enable_map_support: bool = True,
211212
**kwargs: Any,
212213
) -> None:
213214
"""Create an Ibis client connected to PostgreSQL database.
@@ -228,6 +229,9 @@ def do_connect(
228229
PostgreSQL schema to use. If `None`, use the default `search_path`.
229230
autocommit
230231
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.
231235
kwargs
232236
Additional keyword arguments to pass to the backend client connection.
233237
@@ -278,7 +282,7 @@ def do_connect(
278282

279283
self.con.adapters.register_dumper(type(pd.NaT), NatDumper)
280284

281-
self._post_connect()
285+
self._post_connect(enable_map_support)
282286

283287
@util.experimental
284288
@classmethod
@@ -296,19 +300,20 @@ def from_connection(cls, con: psycopg.Connection, /) -> Backend:
296300
new_backend._post_connect()
297301
return new_backend
298302

299-
def _post_connect(self) -> None:
303+
def _post_connect(self, enable_map_support: bool = True) -> None:
300304
import psycopg.types
301305
import psycopg.types.hstore
302306

303307
con = self.con
304308

305309
try:
306310
# 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+
)
312317
except psycopg.Error as e:
313318
warnings.warn(f"Failed to load hstore extension: {e}")
314319
except TypeError:

0 commit comments

Comments
 (0)