diff --git a/django/db/backends/postgresql/operations.py b/django/db/backends/postgresql/operations.py
index 3582460..0c40a58 100644
a
|
b
|
import re
|
2 | 2 | |
3 | 3 | from django.db.backends import BaseDatabaseOperations |
4 | 4 | |
5 | | server_version_re = re.compile(r'PostgreSQL (\d{1,2})\.(\d{1,2})\.?(\d{1,2})?') |
6 | | |
7 | 5 | # This DatabaseOperations class lives in here instead of base.py because it's |
8 | 6 | # used by both the 'postgresql' and 'postgresql_psycopg2' backends. |
9 | 7 | |
… |
… |
class DatabaseOperations(BaseDatabaseOperations):
|
14 | 12 | def _get_postgres_version(self): |
15 | 13 | if self._postgres_version is None: |
16 | 14 | from django.db import connection |
| 15 | from django.db.backends.postgresql.version import get_version |
17 | 16 | cursor = connection.cursor() |
18 | | cursor.execute("SELECT version()") |
19 | | version_string = cursor.fetchone()[0] |
20 | | m = server_version_re.match(version_string) |
21 | | if not m: |
22 | | raise Exception('Unable to determine PostgreSQL version from version() function string: %r' % version_string) |
23 | | self._postgres_version = [int(val) for val in m.groups() if val] |
| 17 | self._postgres_version = get_version(cursor, precision=3) |
24 | 18 | return self._postgres_version |
25 | 19 | postgres_version = property(_get_postgres_version) |
26 | 20 | |
… |
… |
class DatabaseOperations(BaseDatabaseOperations):
|
157 | 151 | NotImplementedError if this is the database in use. |
158 | 152 | """ |
159 | 153 | if aggregate.sql_function == 'STDDEV_POP' or aggregate.sql_function == 'VAR_POP': |
160 | | if self.postgres_version[0] == 8 and self.postgres_version[1] == 2 and self.postgres_version[2] <= 4: |
| 154 | if self.postgres_version[0] == 8 and self.postgres_version[1] == 2 and \ |
| 155 | (self.postgres_version[2] is None or self.postgres_version[2] <= 4): |
161 | 156 | raise NotImplementedError('PostgreSQL 8.2 to 8.2.4 is known to have a faulty implementation of %s. Please upgrade your version of PostgreSQL.' % aggregate.sql_function) |
diff --git a/django/db/backends/postgresql/version.py b/django/db/backends/postgresql/version.py
index ed2ad9e..102ee03 100644
a
|
b
|
import re
|
9 | 9 | # PostgreSQL 8.3.6 |
10 | 10 | # EnterpriseDB 8.3 |
11 | 11 | # PostgreSQL 8.3 beta4 |
12 | | VERSION_RE = re.compile(r'\S+ (\d+)\.(\d+)') |
| 12 | # PostgreSQL 8.4beta1 |
| 13 | VERSION_RE = re.compile(r'\S+ (\d+)\.(\d+)\.?(\d+)?') |
13 | 14 | |
14 | | def get_version(cursor): |
| 15 | def get_version(cursor, precision=2): |
15 | 16 | """ |
16 | 17 | Returns a tuple representing the major and minor version number of the |
17 | 18 | server. For example, (7, 4) or (8, 3). |
18 | 19 | """ |
19 | 20 | cursor.execute("SELECT version()") |
20 | 21 | version = cursor.fetchone()[0] |
21 | | major, minor = VERSION_RE.search(version).groups() |
22 | | return int(major), int(minor) |
23 | | |
| 22 | major, minor, minor2 = VERSION_RE.search(version).groups() |
| 23 | if precision == 1: |
| 24 | return major |
| 25 | elif precision == 2: |
| 26 | return int(major), int(minor) |
| 27 | else: |
| 28 | try: |
| 29 | return int(major), int(minor), int(minor2) |
| 30 | except (ValueError, TypeError): |
| 31 | #raise Exception('Unable to determine PostgreSQL version from version() function string: %r' % version) |
| 32 | return int(major), int(minor), None |