Ticket #10906: 10906-r10633-detect-early-postgresql.diff

File 10906-r10633-detect-early-postgresql.diff, 2.6 KB (added by Richard Davies <richard.davies@…>, 16 years ago)

Improve error message and avoid tests with errors on Postgresql <8.2

  • django/db/backends/postgresql/operations.py

     
    152152    def check_aggregate_support(self, aggregate):
    153153        """Check that the backend fully supports the provided aggregate.
    154154
     155        The population and sample statistics (STDDEV_POP, STDDEV_SAMP,
     156        VAR_POP, VAR_SAMP) were first implemented in Postgres 8.2.
     157
    155158        The implementation of population statistics (STDDEV_POP and VAR_POP)
    156159        under Postgres 8.2 - 8.2.4 is known to be faulty. Raise
    157160        NotImplementedError if this is the database in use.
    158161        """
     162        if aggregate.sql_function == 'STDDEV_POP' or aggregate.sql_function == 'STDDEV_SAMP' or aggregate.sql_function == 'VAR_POP' or aggregate.sql_function == 'VAR_SAMP':
     163            if self.postgres_version[0] < 8 or (self.postgres_version[0] == 8 and self.postgres_version[1] < 2):
     164                raise NotImplementedError('PostgreSQL does not support %s until version 8.2. Please upgrade your version of PostgreSQL.' % aggregate.sql_function)
     165
    159166        if aggregate.sql_function == 'STDDEV_POP' or aggregate.sql_function == 'VAR_POP':
    160167            if self.postgres_version[0] == 8 and self.postgres_version[1] == 2 and self.postgres_version[2] <= 4:
    161168                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)
  • tests/regressiontests/aggregation_regress/models.py

     
    11# coding: utf-8
    22import pickle
    33
    4 from django.db import models
     4from django.db import connection, models
    55from django.conf import settings
    66
    77try:
     
    321321"""
    322322}
    323323
    324 if settings.DATABASE_ENGINE != 'sqlite3':
     324if not (settings.DATABASE_ENGINE == 'sqlite3' or
     325        ((settings.DATABASE_ENGINE == 'postgresql' or settings.DATABASE_ENGINE == 'postgresql_psycopg2') and
     326         (connection.ops.postgres_version[0] < 8 or (connection.ops.postgres_version[0] == 8 and connection.ops.postgres_version[1] < 2)))):
    325327    __test__['API_TESTS'] += """
    326 # Stddev and Variance are not guaranteed to be available for SQLite.
     328# Stddev and Variance are not guaranteed to be available for SQLite or PostgreSQL before 8.2.
    327329
    328330>>> Book.objects.aggregate(StdDev('pages'))
    329331{'pages__stddev': 311.46...}
Back to Top