7
VERSION_RE = re.compile(r'PostgreSQL (\d+)\.(\d+)\.')
7
# This reg-exp is intentionally fairly flexible here.
8
# Needs to be able to handle stuff like:
11
# PostgreSQL 8.3 beta4
13
VERSION_RE = re.compile(r'\S+ (\d+)\.(\d+)\.?(\d+)?')
15
def _parse_version(text):
16
"Internal parsing method. Factored out for testing purposes."
17
major, major2, minor = VERSION_RE.search(text).groups()
19
return int(major), int(major2), int(minor)
20
except (ValueError, TypeError):
21
return int(major), int(major2), None
9
23
def get_version(cursor):
11
Returns a tuple representing the major and minor version number of the
12
server. For example, (7, 4) or (8, 3).
25
Returns a tuple representing the major, minor and revision number of the
26
server. For example, (7, 4, 1) or (8, 3, 4). The revision number will be
27
None in the case of initial releases (e.g., 'PostgreSQL 8.3') or in the
28
case of beta and prereleases ('PostgreSQL 8.4beta1').
14
30
cursor.execute("SELECT version()")
15
version = cursor.fetchone()[0]
16
major, minor = VERSION_RE.search(version).groups()
17
return int(major), int(minor)
31
return _parse_version(cursor.fetchone()[0])