diff options
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql/base.py')
-rw-r--r-- | lib/sqlalchemy/dialects/postgresql/base.py | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index ffd926c46..3ef87620f 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -572,7 +572,7 @@ SQLAlchemy makes available the PostgreSQL ``@@`` operator via the method on any textual column expression. On a PostgreSQL dialect, an expression like the following:: - select([sometable.c.text.match("search string")]) + select(sometable.c.text.match("search string")) will emit to the database:: @@ -582,9 +582,7 @@ The PostgreSQL text search functions such as ``to_tsquery()`` and ``to_tsvector()`` are available explicitly using the standard :data:`.func` construct. For example:: - select([ - func.to_tsvector('fat cats ate rats').match('cat & rat') - ]) + select(func.to_tsvector('fat cats ate rats').match('cat & rat')) Emits the equivalent of:: @@ -594,7 +592,7 @@ The :class:`_postgresql.TSVECTOR` type can provide for explicit CAST:: from sqlalchemy.dialects.postgresql import TSVECTOR from sqlalchemy import select, cast - select([cast("some text", TSVECTOR)]) + select(cast("some text", TSVECTOR)) produces a statement equivalent to:: @@ -615,7 +613,7 @@ In order to provide for this explicit query planning, or to use different search strategies, the ``match`` method accepts a ``postgresql_regconfig`` keyword argument:: - select([mytable.c.id]).where( + select(mytable.c.id).where( mytable.c.title.match('somestring', postgresql_regconfig='english') ) @@ -627,7 +625,7 @@ Emits the equivalent of:: One can also specifically pass in a `'regconfig'` value to the ``to_tsvector()`` command as the initial argument:: - select([mytable.c.id]).where( + select(mytable.c.id).where( func.to_tsvector('english', mytable.c.title )\ .match('somestring', postgresql_regconfig='english') ) @@ -941,7 +939,7 @@ is not available yet in sqlalchemy, however the :func:`_expression.literal_column` function with the name of the table may be used in its place:: - select(['*']).select_from(func.my_function(literal_column('my_table'))) + select('*').select_from(func.my_function(literal_column('my_table'))) Will generate the SQL:: @@ -2280,6 +2278,10 @@ class PGDDLCompiler(compiler.DDLCompiler): whereclause = index.dialect_options["postgresql"]["where"] if whereclause is not None: + whereclause = coercions.expect( + roles.DDLExpressionRole, whereclause + ) + where_compiled = self.sql_compiler.process( whereclause, include_table=False, literal_binds=True ) @@ -2717,7 +2719,6 @@ class PGDialect(default.DefaultDialect): supports_sequences = True sequences_optional = True - sequence_default_column_type = INTEGER preexecute_autoincrement_sequences = True postfetch_lastrowid = False @@ -3665,9 +3666,10 @@ class PGDialect(default.DefaultDialect): IDX_SQL = """ SELECT i.relname as relname, - ix.indisunique, ix.indexprs, ix.indpred, + ix.indisunique, ix.indexprs, a.attname, a.attnum, c.conrelid, ix.indkey::varchar, ix.indoption::varchar, i.reloptions, am.amname, + pg_get_expr(ix.indpred, ix.indrelid), %s as indnkeyatts FROM pg_class t @@ -3710,7 +3712,6 @@ class PGDialect(default.DefaultDialect): idx_name, unique, expr, - prd, col, col_num, conrelid, @@ -3718,6 +3719,7 @@ class PGDialect(default.DefaultDialect): idx_option, options, amname, + filter_definition, indnkeyatts, ) = row @@ -3730,13 +3732,6 @@ class PGDialect(default.DefaultDialect): sv_idx_name = idx_name continue - if prd and not idx_name == sv_idx_name: - util.warn( - "Predicate of partial index %s ignored during reflection" - % idx_name - ) - sv_idx_name = idx_name - has_idx = idx_name in indexes index = indexes[idx_name] if col is not None: @@ -3794,6 +3789,9 @@ class PGDialect(default.DefaultDialect): if amname and amname != "btree": index["amname"] = amname + if filter_definition: + index["postgresql_where"] = filter_definition + result = [] for name, idx in indexes.items(): entry = { @@ -3818,6 +3816,10 @@ class PGDialect(default.DefaultDialect): entry.setdefault("dialect_options", {})[ "postgresql_using" ] = idx["amname"] + if "postgresql_where" in idx: + entry.setdefault("dialect_options", {})[ + "postgresql_where" + ] = idx["postgresql_where"] result.append(entry) return result |