From c117068dbe1cb70538af46988ea0ba0b581a7455 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Wed, 17 Jan 2007 18:47:36 +0000 Subject: [PATCH] - fix to the initial checkfirst for tables to take current schema into account [ticket:424] --- CHANGES | 1 + lib/sqlalchemy/databases/postgres.py | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index 97710b56cf..0dc9411c84 100644 --- a/CHANGES +++ b/CHANGES @@ -23,6 +23,7 @@ - added an NVarchar type (produces NVARCHAR), also MSUnicode which provides Unicode-translation for the NVarchar regardless of dialect convert_unicode setting. - postgres: + - fix to the initial checkfirst for tables to take current schema into account [ticket:424] - postgres has an optional "server_side_cursors=True" flag which will utilize server side cursors. these are appropriate for fetching only partial results and are necessary for working with very large unbounded result sets. diff --git a/lib/sqlalchemy/databases/postgres.py b/lib/sqlalchemy/databases/postgres.py index 94519a5acc..6f22113b6b 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): -- 2.47.2