]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Make the postgres_where attribute to Index private to postgres module by using a...
authorAnts Aasma <ants.aasma@gmail.com>
Mon, 1 Oct 2007 16:29:26 +0000 (16:29 +0000)
committerAnts Aasma <ants.aasma@gmail.com>
Mon, 1 Oct 2007 16:29:26 +0000 (16:29 +0000)
lib/sqlalchemy/databases/postgres.py
lib/sqlalchemy/schema.py

index 76f17bb5bfa62b32a820ad11e56e6769cd3ade2e..9292e6ea49135f622044b7c734873b2535f9129c 100644 (file)
@@ -4,6 +4,14 @@
 # This module is part of SQLAlchemy and is released under
 # the MIT License: http://www.opensource.org/licenses/mit-license.php
 
+"""Support for the PostgreSQL database.
+
+PostgreSQL supports partial indexes. To create them pass a posgres_where
+option to the Index constructor::
+
+  Index('my_index', my_table.c.id, postgres_where=tbl.c.value > 10)
+"""
+
 import re, random, warnings, string
 
 from sqlalchemy import sql, schema, exceptions, util
@@ -622,8 +630,9 @@ class PGSchemaGenerator(compiler.SchemaGenerator):
                     % (preparer.format_index(index),
                        preparer.format_table(index.table),
                        string.join([preparer.format_column(c) for c in index.columns], ', ')))
-        if index.postgres_where is not None:
-            compiler = self._compile(index.postgres_where, None)
+        whereclause = index.kwargs.get('postgres_where', None)
+        if whereclause is not None:
+            compiler = self._compile(whereclause, None)
             # this might belong to the compiler class
             inlined_clause = str(compiler) % dict((key,bind.value) for key,bind in compiler.binds.iteritems())
             self.append(" WHERE " + inlined_clause)
index fce181cbb8dd28e55dc8205c47a41db1f3cf175f..8ca5567e473d3954f3dd77cd888750b03a411f1f 100644 (file)
@@ -956,7 +956,9 @@ class Index(SchemaItem):
         self.columns = []
         self.table = None
         self.unique = kwargs.pop('unique', False)
-        self.postgres_where = kwargs.pop('postgres_where', None)
+
+        self.kwargs = kwargs
+
         self._init_items(*columns)
 
     def _init_items(self, *args):