[FIX] core: only check table existance in public schema

This allow the use of tables defined in other schemas, like `domains`,
already defined in `information_schema`.

See #16651
This commit is contained in:
Christophe Simonis
2017-09-11 14:55:49 +02:00
parent 45d706a607
commit fdc4ef97c9
+7 -7
View File
@@ -24,19 +24,19 @@ _CONFDELTYPES = {
def existing_tables(cr, tablenames):
""" Return the names of existing tables among ``tablenames``. """
query = """
SELECT relname
FROM pg_class
WHERE relname IN %s
AND relkind IN ('r', 'v', 'm')
SELECT c.relname
FROM pg_class c
JOIN pg_namespace n ON (n.oid = c.relnamespace)
WHERE c.relname IN %s
AND c.relkind IN ('r', 'v', 'm')
AND n.nspname = 'public'
"""
cr.execute(query, [tuple(tablenames)])
return [row[0] for row in cr.fetchall()]
def table_exists(cr, tablename):
""" Return whether the given table exists. """
query = "SELECT 1 FROM pg_class WHERE relkind IN ('r', 'v', 'm') AND relname=%s"
cr.execute(query, (tablename,))
return cr.rowcount
return len(existing_tables(cr, {tablename})) == 1
def table_kind(cr, tablename):
""" Return the kind of a table: ``'r'`` (regular table), ``'v'`` (view),