4 |
4 |
5 # This DatabaseOperations class lives in here instead of base.py because it's |
5 # This DatabaseOperations class lives in here instead of base.py because it's |
6 # used by both the 'postgresql' and 'postgresql_psycopg2' backends. |
6 # used by both the 'postgresql' and 'postgresql_psycopg2' backends. |
7 |
7 |
8 class DatabaseOperations(BaseDatabaseOperations): |
8 class DatabaseOperations(BaseDatabaseOperations): |
9 def __init__(self): |
9 def __init__(self, connection): |
|
10 super(DatabaseOperations, self).__init__() |
10 self._postgres_version = None |
11 self._postgres_version = None |
|
12 self.connection = connection |
11 |
13 |
12 def _get_postgres_version(self): |
14 def _get_postgres_version(self): |
13 if self._postgres_version is None: |
15 if self._postgres_version is None: |
14 from django.db import connection |
|
15 from django.db.backends.postgresql.version import get_version |
16 from django.db.backends.postgresql.version import get_version |
16 cursor = connection.cursor() |
17 cursor = self.connection.cursor() |
17 self._postgres_version = get_version(cursor) |
18 self._postgres_version = get_version(cursor) |
18 return self._postgres_version |
19 return self._postgres_version |
19 postgres_version = property(_get_postgres_version) |
20 postgres_version = property(_get_postgres_version) |
20 |
21 |
21 def date_extract_sql(self, lookup_type, field_name): |
22 def date_extract_sql(self, lookup_type, field_name): |
160 |
161 |
161 if aggregate.sql_function in ('STDDEV_POP', 'VAR_POP'): |
162 if aggregate.sql_function in ('STDDEV_POP', 'VAR_POP'): |
162 if self.postgres_version[0:2] == (8,2): |
163 if self.postgres_version[0:2] == (8,2): |
163 if self.postgres_version[2] is None or self.postgres_version[2] <= 4: |
164 if self.postgres_version[2] is None or self.postgres_version[2] <= 4: |
164 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) |
165 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) |
|
166 |
|
167 def max_name_length(self): |
|
168 """ |
|
169 Returns the maximum length of an identifier. |
|
170 |
|
171 Note that the maximum length of an identifier is 63 by default, but can |
|
172 be changed by recompiling PostgreSQL after editing the NAMEDATALEN |
|
173 macro in src/include/pg_config_manual.h . |
|
174 |
|
175 This implementation simply returns 63, but can easily be overridden by a |
|
176 custom database backend that inherits most of its behavior from this one. |
|
177 """ |
|
178 |
|
179 return 63 |