diff options
author | Marko Kreen | 2012-07-05 15:25:32 +0000 |
---|---|---|
committer | Marko Kreen | 2012-07-05 15:25:32 +0000 |
commit | e85a1184a070779ac21528662c7cce682cbff308 (patch) | |
tree | 70298e7f3ce30d3e7bcc3a0074118c31b75ee421 | |
parent | 551a0d0f2adb892a0fb9c4fca5257cbc534ec558 (diff) |
skytools.exists_view(): new function
-rw-r--r-- | python/skytools/__init__.py | 1 | ||||
-rw-r--r-- | python/skytools/sqltools.py | 12 |
2 files changed, 12 insertions, 1 deletions
diff --git a/python/skytools/__init__.py b/python/skytools/__init__.py index 84ed00de..73a0e9ed 100644 --- a/python/skytools/__init__.py +++ b/python/skytools/__init__.py @@ -108,6 +108,7 @@ _symbols = { 'exists_table': 'skytools.sqltools:exists_table', 'exists_temp_table': 'skytools.sqltools:exists_temp_table', 'exists_type': 'skytools.sqltools:exists_type', + 'exists_view': 'skytools.sqltools:exists_view', 'fq_name': 'skytools.sqltools:fq_name', 'fq_name_parts': 'skytools.sqltools:fq_name_parts', 'full_copy': 'skytools.sqltools:full_copy', diff --git a/python/skytools/sqltools.py b/python/skytools/sqltools.py index f8014eb4..558c0dc0 100644 --- a/python/skytools/sqltools.py +++ b/python/skytools/sqltools.py @@ -13,7 +13,7 @@ except ImportError: __all__ = [ "fq_name_parts", "fq_name", "get_table_oid", "get_table_pkeys", "get_table_columns", "exists_schema", "exists_table", "exists_type", - "exists_sequence", "exists_temp_table", + "exists_sequence", "exists_temp_table", "exists_view", "exists_function", "exists_language", "Snapshot", "magic_insert", "CopyPipe", "full_copy", "DBObject", "DBSchema", "DBTable", "DBFunction", "DBLanguage", "db_install", "installer_find_file", "installer_apply_file", @@ -137,6 +137,16 @@ def exists_sequence(curs, seq_name): res = curs.fetchone() return res[0] +def exists_view(curs, view_name): + """Does view exists?""" + schema, name = fq_name_parts(view_name) + q = """select count(1) from pg_namespace n, pg_class c + where c.relnamespace = n.oid and c.relkind = 'v' + and n.nspname = %s and c.relname = %s""" + curs.execute(q, [schema, name]) + res = curs.fetchone() + return res[0] + def exists_type(curs, type_name): """Does type exists?""" schema, name = fq_name_parts(type_name) |