Skip to content

Commit 380c553

Browse files
committed
Add Amazon Redshift detection.
Fixes: #29.
1 parent 749d857 commit 380c553

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

asyncpg/connection.py

+15-7
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ def _get_reset_query(self):
513513
_reset_query.append('ROLLBACK;')
514514
if caps.advisory_locks:
515515
_reset_query.append('SELECT pg_advisory_unlock_all();')
516-
if caps.cursors:
516+
if caps.sql_close_all:
517517
_reset_query.append('CLOSE ALL;')
518518
if caps.notifications and caps.plpgsql:
519519
_reset_query.append('''
@@ -844,30 +844,38 @@ def _create_future(loop):
844844

845845
ServerCapabilities = collections.namedtuple(
846846
'ServerCapabilities',
847-
['advisory_locks', 'cursors', 'notifications', 'plpgsql', 'sql_reset'])
847+
['advisory_locks', 'notifications', 'plpgsql', 'sql_reset',
848+
'sql_close_all'])
848849
ServerCapabilities.__doc__ = 'PostgreSQL server capabilities.'
849850

850851

851852
def _detect_server_capabilities(server_version, connection_settings):
852-
if hasattr(connection_settings, 'crdb_version'):
853+
if hasattr(connection_settings, 'padb_revision'):
854+
# Amazon Redshift detected.
855+
advisory_locks = False
856+
notifications = False
857+
plpgsql = False
858+
sql_reset = True
859+
sql_close_all = False
860+
elif hasattr(connection_settings, 'crdb_version'):
853861
# CocroachDB detected.
854862
advisory_locks = False
855-
cursors = False
856863
notifications = False
857864
plpgsql = False
858865
sql_reset = False
866+
sql_close_all = False
859867
else:
860868
# Standard PostgreSQL server assumed.
861869
advisory_locks = True
862-
cursors = True
863870
notifications = True
864871
plpgsql = True
865872
sql_reset = True
873+
sql_close_all = True
866874

867875
return ServerCapabilities(
868876
advisory_locks=advisory_locks,
869-
cursors=cursors,
870877
notifications=notifications,
871878
plpgsql=plpgsql,
872-
sql_reset=sql_reset
879+
sql_reset=sql_reset,
880+
sql_close_all=sql_close_all
873881
)

0 commit comments

Comments
 (0)