[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:
+7
-7
@@ -24,19 +24,19 @@ _CONFDELTYPES = {
|
|||||||
def existing_tables(cr, tablenames):
|
def existing_tables(cr, tablenames):
|
||||||
""" Return the names of existing tables among ``tablenames``. """
|
""" Return the names of existing tables among ``tablenames``. """
|
||||||
query = """
|
query = """
|
||||||
SELECT relname
|
SELECT c.relname
|
||||||
FROM pg_class
|
FROM pg_class c
|
||||||
WHERE relname IN %s
|
JOIN pg_namespace n ON (n.oid = c.relnamespace)
|
||||||
AND relkind IN ('r', 'v', 'm')
|
WHERE c.relname IN %s
|
||||||
|
AND c.relkind IN ('r', 'v', 'm')
|
||||||
|
AND n.nspname = 'public'
|
||||||
"""
|
"""
|
||||||
cr.execute(query, [tuple(tablenames)])
|
cr.execute(query, [tuple(tablenames)])
|
||||||
return [row[0] for row in cr.fetchall()]
|
return [row[0] for row in cr.fetchall()]
|
||||||
|
|
||||||
def table_exists(cr, tablename):
|
def table_exists(cr, tablename):
|
||||||
""" Return whether the given table exists. """
|
""" Return whether the given table exists. """
|
||||||
query = "SELECT 1 FROM pg_class WHERE relkind IN ('r', 'v', 'm') AND relname=%s"
|
return len(existing_tables(cr, {tablename})) == 1
|
||||||
cr.execute(query, (tablename,))
|
|
||||||
return cr.rowcount
|
|
||||||
|
|
||||||
def table_kind(cr, tablename):
|
def table_kind(cr, tablename):
|
||||||
""" Return the kind of a table: ``'r'`` (regular table), ``'v'`` (view),
|
""" Return the kind of a table: ``'r'`` (regular table), ``'v'`` (view),
|
||||||
|
|||||||
Reference in New Issue
Block a user