summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects/postgresql/base.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2011-10-23 16:57:48 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2011-10-23 16:57:48 -0400
commit8301651428be5396b76f7d20c8f61b5558d5a971 (patch)
tree29216f336a8c3e196da7011a971fe6a4cd947ba0 /lib/sqlalchemy/dialects/postgresql/base.py
parent2f2505893b9290c6147ec439a275b98c70c11bc5 (diff)
downloadsqlalchemy-8301651428be5396b76f7d20c8f61b5558d5a971.tar.gz
- [feature] Added new support for remote "schemas":
- MetaData() accepts "schema" and "quote_schema" arguments, which will be applied to the same-named arguments of a Table or Sequence which leaves these at their default of ``None``. - Sequence accepts "quote_schema" argument - tometadata() for Table will use the "schema" of the incoming MetaData for the new Table if the schema argument is explicitly "None" - Added CreateSchema and DropSchema DDL constructs - these accept just the string name of a schema and a "quote" flag. - When using default "schema" with MetaData, ForeignKey will also assume the "default" schema when locating remote table. This allows the "schema" argument on MetaData to be applied to any set of Table objects that otherwise don't have a "schema". - a "has_schema" method has been implemented on dialect, but only works on Postgresql so far. Courtesy Manlio Perillo, [ticket:1679]
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql/base.py')
-rw-r--r--lib/sqlalchemy/dialects/postgresql/base.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py
index 7cc4a1e68..3ae60f696 100644
--- a/lib/sqlalchemy/dialects/postgresql/base.py
+++ b/lib/sqlalchemy/dialects/postgresql/base.py
@@ -952,6 +952,19 @@ class PGDialect(default.DefaultDialect):
def _get_default_schema_name(self, connection):
return connection.scalar("select current_schema()")
+ def has_schema(self, connection, schema):
+ cursor = connection.execute(
+ sql.text(
+ "select nspname from pg_namespace where lower(nspname)=:schema",
+ bindparams=[
+ sql.bindparam(
+ 'schema', unicode(schema.lower()),
+ type_=sqltypes.Unicode)]
+ )
+ )
+
+ return bool(cursor.first())
+
def has_table(self, connection, table_name, schema=None):
# seems like case gets folded in pg_class...
if schema is None: