在调用sql脚本时动态生成临时表处理

定义一张临时表,往里插数据,返回表名

temp_terms_table_name = insert_keywords_into_table(keywords, batch_id, audience_id)
sql_array << "SELECT 'opx:'||click_opxpid, 'aids', #{audience_id} FROM dw.clickdatas c INNER JOIN dw.searcher se ON c.searcher_id = se.id INNER JOIN #{temp_terms_table_name} t on position(t.term in c.leading_keyword) != 0 WHERE client_id = #{a.client_id} AND c_date >= #{int_date} GROUP BY 1"




def insert_keywords_into_table(arr_keywords, batch_id, audience_id)
str_table_name = "workspace.audience_terms_#{batch_id}_#{audience_id}"
Audience.connection.execute("create table #{str_table_name} (term text) with (appendonly = true, compresslevel = 6);") if @keywords_table_created == false
@keywords_table_created = true
keywords_string = arr_keywords.collect{|k| "(#{SearchenginePpc.connection.quote(k)})"}.join(",")
Audience.connection.execute("insert into #{str_table_name} values #{keywords_string};")
return str_table_name
end
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值