diff options
author | mike bayer <mike_mp@zzzcomputing.com> | 2016-06-08 13:21:12 -0400 |
---|---|---|
committer | Gerrit Code Review <gerrit2@ln3.zzzcomputing.com> | 2016-06-08 13:21:12 -0400 |
commit | 24d29a63b6a30d1f1cd4d1097c021be0302c7922 (patch) | |
tree | f02d6ed5665cec1906371d1f97bcb39f5a725b1a /lib/sqlalchemy/dialects/postgresql | |
parent | c99fc44e170be61696206872701ff75e4c8a3711 (diff) | |
parent | 824c8664ed18f115fc109c46cec0c25d223f8aad (diff) | |
download | sqlalchemy-24d29a63b6a30d1f1cd4d1097c021be0302c7922.tar.gz |
Merge "Support normal /materialized views in PG separately"
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql')
-rw-r--r-- | lib/sqlalchemy/dialects/postgresql/base.py | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index d613aac92..ec20c4b7a 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -1557,6 +1557,24 @@ class PGInspector(reflection.Inspector): schema = schema or self.default_schema_name return self.dialect._get_foreign_table_names(self.bind, schema) + def get_view_names(self, schema=None, include=('plain', 'materialized')): + """Return all view names in `schema`. + + :param schema: Optional, retrieve names from a non-default schema. + For special quoting, use :class:`.quoted_name`. + + :param include: specify which types of views to return. Passed + as a string value (for a single type) or a tuple (for any number + of types). Defaults to ``('plain', 'materialized')``. + + .. versionadded:: 1.1 + + """ + + return self.dialect.get_view_names(self.bind, schema, + info_cache=self.info_cache, + include=include) + class CreateEnumType(schema._CreateDropBase): __visit_name__ = "create_enum_type" @@ -1958,11 +1976,27 @@ class PGDialect(default.DefaultDialect): return [name for name, in result] @reflection.cache - def get_view_names(self, connection, schema=None, **kw): + def get_view_names( + self, connection, schema=None, + include=('plain', 'materialized'), **kw): + + include_kind = {'plain': 'v', 'materialized': 'm'} + try: + kinds = [include_kind[i] for i in util.to_list(include)] + except KeyError: + raise ValueError( + "include %r unknown, needs to be a sequence containing " + "one or both of 'plain' and 'materialized'" % (include,)) + if not kinds: + raise ValueError( + "empty include, needs to be a sequence containing " + "one or both of 'plain' and 'materialized'") + result = connection.execute( sql.text("SELECT c.relname FROM pg_class c " "JOIN pg_namespace n ON n.oid = c.relnamespace " - "WHERE n.nspname = :schema AND c.relkind IN ('v', 'm')" + "WHERE n.nspname = :schema AND c.relkind IN (%s)" % + (", ".join("'%s'" % elem for elem in kinds)) ).columns(relname=sqltypes.Unicode), schema=schema if schema is not None else self.default_schema_name) return [name for name, in result] |