From c117068dbe1cb70538af46988ea0ba0b581a7455 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Wed, 17 Jan 2007 18:47:36 +0000 Subject: - fix to the initial checkfirst for tables to take current schema into account [ticket:424] --- lib/sqlalchemy/databases/postgres.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'lib/sqlalchemy/databases/postgres.py') diff --git a/lib/sqlalchemy/databases/postgres.py b/lib/sqlalchemy/databases/postgres.py index 94519a5ac..6f22113b6 100644 --- a/lib/sqlalchemy/databases/postgres.py +++ b/lib/sqlalchemy/databases/postgres.py @@ -298,9 +298,12 @@ class PGDialect(ansisql.ANSIDialect): def dbapi(self): return self.module - def has_table(self, connection, table_name): - # TODO: why are we case folding here ? - cursor = connection.execute("""select relname from pg_class where lower(relname) = %(name)s""", {'name':table_name.lower()}) + def has_table(self, connection, table_name, schema=None): + # seems like case gets folded in pg_class... + if schema is None: + cursor = connection.execute("""select relname from pg_class c join pg_namespace n on n.oid=c.relnamespace where n.nspname=current_schema() and relname=%(name)s""", {'name':table_name.lower()}); + else: + cursor = connection.execute("""select relname from pg_class c join pg_namespace n on n.oid=c.relnamespace where n.nspname=%(schema)s and relname=%(name)s""", {'name':table_name.lower(), 'schema':schema}); return bool( not not cursor.rowcount ) def has_sequence(self, connection, sequence_name): -- cgit v1.2.1