Ticket #6433: postgres-versions.diff
File postgres-versions.diff, 1.4 KB (added by , 17 years ago) |
---|
-
django/db/backends/postgresql/operations.py
1 1 from django.db.backends import BaseDatabaseOperations 2 import re 2 3 3 4 # This DatabaseOperations class lives in here instead of base.py because it's 4 5 # used by both the 'postgresql' and 'postgresql_psycopg2' backends. 5 6 7 # re string to match the numerical portion of the version numbers of PostgreSQL 8 # 9 server_version_re = re.compile(r'PostgreSQL (\d{1,2})\.(\d{1,2})\.?(\d{1,2})?') 10 6 11 class DatabaseOperations(BaseDatabaseOperations): 7 12 def __init__(self): 8 13 self._postgres_version = None … … 12 17 from django.db import connection 13 18 cursor = connection.cursor() 14 19 cursor.execute("SELECT version()") 15 self._postgres_version = [int(val) for val in cursor.fetchone()[0].split()[1].split('.')] 20 version_string = cursor.fetchone()[0] 21 m = server_version_re.match(version_string) 22 if not m: 23 raise Exception('Unable to determine PostgreSQL version from version() function string: %r' % version_string) 24 self._postgres_version = [int(val) for val in m.groups() if val != None] 16 25 return self._postgres_version 17 26 postgres_version = property(_get_postgres_version) 18 27