diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2007-01-17 18:47:36 +0000 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2007-01-17 18:47:36 +0000 |
| commit | c117068dbe1cb70538af46988ea0ba0b581a7455 (patch) | |
| tree | e528ade59c2f40341073bf1db7773116f9e7bb30 /lib/sqlalchemy/databases/postgres.py | |
| parent | 3d22b16255c98cd760fdd55657c24b8c5e131ac1 (diff) | |
| download | sqlalchemy-c117068dbe1cb70538af46988ea0ba0b581a7455.tar.gz | |
- fix to the initial checkfirst for tables to take current schema into account [ticket:424]
Diffstat (limited to 'lib/sqlalchemy/databases/postgres.py')
| -rw-r--r-- | lib/sqlalchemy/databases/postgres.py | 9 |
1 files changed, 6 insertions, 3 deletions
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): |
