如何将sql插入语句转换为1个liner并在python中逐个运行?
嗨,我是 python 新手,所以问这个问题。我已在文件中插入查询。 我必须将它们一一处决。 你能帮我看看我该怎么做吗?它们保存在文本文件中。他们不在 1 班轮中。我们如何将它们制作成 1 个衬垫或将它们转换为数据帧?
例子: 插入语句.txt
INSERT INTO imedical_cleansing_rule_metadata
(
Data_Set_Name,
Region,
Layer,
Table_Name,
Column_Name,
Column_Seq,
EC2_Source_Path,
EC2_Target_Path,
Is_Active,
s3_tgt_path,
Rule,
Spectrum_Table_Name,
Sub_Rule
)
VALUES
(
'JGVCC',
'ASPAC',
'Raw_Layer',
'DM_GENESYS_CONVERSTION_AGG',
'queue_name',
2,
'/medaff/Scripts/Incoming_Src_Files/',
'/medaff/eureka/RawLayer/JGVCC/ASPAC/Genesys/DM_GENESYS_CONVERSTION_AGG/',
'N',
's3://itx-{}-jg-aspac/jgvcc/Raw_Layer/DM_GENESYS_CONVERSTION_AGG/',
'rule1;rule3;rule4;rule2;rule6;rule19',
'lnd_jgvcc_aspac_genesys_call_detail',
NULL
);
INSERT INTO imedical_cleansing_rule_metadata
(
Data_Set_Name,
Region,
Layer,
Table_Name,
Column_Name,
Column_Seq,
EC2_Source_Path,
EC2_Target_Path,
Is_Active,
s3_tgt_path,
Rule,
Spectrum_Table_Name,
Sub_Rule
)
VALUES
(
'JGVCC',
'ASPAC',
'Raw_Layer',
'DM_EUAVCC_CASE_CRM',
'parent_case_number',
1,
'/medaff/Scripts/Incoming_Src_Files/',
'/medaff/eureka/RawLayer/JGVCC/ASPAC/CRM/DM_EUAVCC_CASE_CRM/',
'N',
's3://itx-{}-jg-aspac/jgvcc/Raw_Layer/DM_EUAVCC_CASE_CRM/',
'rule1;rule3;rule4;rule2;rule6;rule19',
'lnd_jgvcc_aspac_crm_activity',
NULL
);
Hi I am new in python so asking this question. I have insert query in file.
I have to execute them one by one.
Could you please help me how can I do this? They are saved in text file. They aren't in 1 liner. How can we make them in 1 liner or convert them into dataframe?
Example:
insert_statement.txt
INSERT INTO imedical_cleansing_rule_metadata
(
Data_Set_Name,
Region,
Layer,
Table_Name,
Column_Name,
Column_Seq,
EC2_Source_Path,
EC2_Target_Path,
Is_Active,
s3_tgt_path,
Rule,
Spectrum_Table_Name,
Sub_Rule
)
VALUES
(
'JGVCC',
'ASPAC',
'Raw_Layer',
'DM_GENESYS_CONVERSTION_AGG',
'queue_name',
2,
'/medaff/Scripts/Incoming_Src_Files/',
'/medaff/eureka/RawLayer/JGVCC/ASPAC/Genesys/DM_GENESYS_CONVERSTION_AGG/',
'N',
's3://itx-{}-jg-aspac/jgvcc/Raw_Layer/DM_GENESYS_CONVERSTION_AGG/',
'rule1;rule3;rule4;rule2;rule6;rule19',
'lnd_jgvcc_aspac_genesys_call_detail',
NULL
);
INSERT INTO imedical_cleansing_rule_metadata
(
Data_Set_Name,
Region,
Layer,
Table_Name,
Column_Name,
Column_Seq,
EC2_Source_Path,
EC2_Target_Path,
Is_Active,
s3_tgt_path,
Rule,
Spectrum_Table_Name,
Sub_Rule
)
VALUES
(
'JGVCC',
'ASPAC',
'Raw_Layer',
'DM_EUAVCC_CASE_CRM',
'parent_case_number',
1,
'/medaff/Scripts/Incoming_Src_Files/',
'/medaff/eureka/RawLayer/JGVCC/ASPAC/CRM/DM_EUAVCC_CASE_CRM/',
'N',
's3://itx-{}-jg-aspac/jgvcc/Raw_Layer/DM_EUAVCC_CASE_CRM/',
'rule1;rule3;rule4;rule2;rule6;rule19',
'lnd_jgvcc_aspac_crm_activity',
NULL
);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果所有查询都由一个空行分隔,您可以读取它们并将其存储在列表中:
If all queries are separated by one blank line, you could read and store them in a list: