sql - 如何使用带有动态参数的 ansible postgress 查询
问题描述
我有一些 ansible 角色,我需要动态传递部分数据库名称,由于某些限制,我无法摆脱 sql 文件,所以我尝试了下面的代码但没有用
- name: Select query to my_test db with named_args
postgresql_query:
db: test_db
path_to_script: myscript.sql
named_args:
schema: mytest
table_pfix: test
myscript.sql 文件是
set SCHEMA %(schema)s;
select count(*) from my_%(table_pfix)s;
当我运行这个角色时,我收到语法错误
{"changed" : false, "msg": "can not execute sql schema 'set SCHEMA %(schema)s;\nslect count(*) from my_%(table_pfix)s;'
{'scheam':mytest,'table_pfix':'test'}: synatax error at near \"'my_test'\" LINE 2 : slect count(*) from my_'test';
解决方案
推荐阅读
- javascript - 如何在包含具有数组值的子对象的对象中搜索值
- flutter - 为什么使用这个简单的 initState 代码会导致 Flutter 崩溃?
- vba - InternetExplorer html attribute change
- python - 为什么不能从python中的主类导入子类
- amazon-web-services - 为什么我的 lambda 函数无法访问 S3?
- java - Pfx 基本编码字符串到 p12 证书
- c - 将递归函数转换为循环(三元运算符)
- provisioning-profile - 多个帐户上的 iOS 捆绑标识符
- javascript - “free robux”诈骗网站上使用的反混淆算法
- shell - 无法在 openstack heat 模板的 user_data 中运行命令