python-Jinja2-将列列表传递给select语句
发布时间:2022-05-04 15:33:14 255
相关标签: # node.js
我想为随机集成创建一些数据健全性检查。为此,我需要创建足够灵活的查询,以便在不同的表中运行。我正在使用jinja2创建一些宏,以便将列和表传递给这些查询。
Now my problem is if i want to check for duplicate data-points, in all columns like:
SELECT username, email, COUNT(*)
FROM users
GROUP BY username, email
HAVING COUNT(*) > 1
i would need to create a macro that allowed me to pass multiple columns to select statement and i don't know how to get it.I was wondering if i could create a .yaml with the table name + columns and make a macro that would fecth that data
For now i have this working
{%- macro duplicates_ids(table, column) -%}
select{{ column }},count(*)
from {{ table }}group by {{ column }}having count(*) >1
{%- endmacro -%}
Thank you all in advance
So then i can just define the table name and the column to test the table.
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报