问题是在执行Ansible的数据操作过程中出现SQLParseError错误,错误信息提示“PostgreSQL不支持表名中超过三个点号”的情况。解决方法是修改Ansible的源代码,将该错误信息捕获,并通过自定义函数替换掉表名中的多个点号。代码示例如下:
try: result = cursor.execute(sql, args) except psycopg2.Error as exc: if isinstance(exc, psycopg2.ProgrammingError) and 'relation' in str(exc): raise self._rel_does_not_exist(exc, statement) elif isinstance(exc, psycopg2.InternalError) and 'does not support' in str(exc): exc_message = str(exc) if "table with more than 3 dots" in exc_message: exc_message = exc_message.replace("table with more than 3 dots", "table with multiple dots") exc = psycopg2.InternalError(exc_message) raise self._translate_exception(exc, statement)
def replace_dots(identifier): return re.sub(r'.{2,}', '.', identifier)
def _get_table_column_priv(self, table): # parse table name, handle when table name contains schema if '.' in table: schema, table = table.split('.') schema = replace_dots(schema) table = replace_dots(table) else: schema = 'public'
# get privileges for columns of the table
query = self.owner_user_query("SELECT attname, format_type(atttypid, atttypmod)"
" FROM pg_attribute WHERE attrelid ="
" (SELECT oid FROM pg_class c JOIN pg_namespace n"
" ON n.oid=c.relnamespace WHERE n.nspname = %s AND relname = %s)"
" AND NOT attisdropped", (schema, table))