Skip to content
This repository was archived by the owner on May 5, 2022. It is now read-only.

Commit e1289d4

Browse files
committed
feat: using SELECT version() to get server_version
1 parent d343c46 commit e1289d4

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

sqlalchemy_trino/dialect.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import re
12
from textwrap import dedent
23
from typing import *
34

@@ -6,7 +7,6 @@
67
from sqlalchemy.engine.default import DefaultDialect, DefaultExecutionContext
78
from sqlalchemy.engine.url import URL
89
from trino.auth import BasicAuthentication
9-
import re
1010

1111
from . import compiler
1212
from . import datatype
@@ -60,7 +60,7 @@ class TrinoDialect(DefaultDialect):
6060
supports_multivalues_insert = True
6161

6262
# Version parser
63-
__version_pattern = re.compile('(\d+).*')
63+
__version_pattern = re.compile(r'(\d+).*')
6464

6565
@classmethod
6666
def dbapi(cls):
@@ -262,14 +262,10 @@ def has_sequence(self, connection: Connection,
262262
return False
263263

264264
def _get_server_version_info(self, connection: Connection) -> Tuple[int, ...]:
265-
query = dedent('''
266-
SELECT *
267-
FROM system.runtime.nodes
268-
WHERE coordinator = true AND state = 'active'
269-
''').strip()
270-
res = connection.execute(sql.text(query)).first()
271-
parsed_version = self.__version_pattern.match(res.node_version)
272-
version = int(parsed_version.group(1)) if parsed_version else 0
265+
query = 'SELECT version()'
266+
res = connection.execute(sql.text(query)).scalar()
267+
match = self.__version_pattern.match(res)
268+
version = int(match.group(1)) if match else 0
273269
return tuple([version])
274270

275271
def _get_default_schema_name(self, connection: Connection) -> Optional[str]:

0 commit comments

Comments
 (0)