猿问

Go 模板连接切片中的查询

我想将我的 SQL 查询与UNION ALLgolang http://golang.org/pkg/text/template/ 连接起来


例如,我有:


var slice1 = []string{"2014-01-01", "2014-01-02", "2014-01-03"}

var slice2 = []string{"20140101", "20140102", "20140103"}

并查询:


select {{.date}} as date, itemid, price

from orderhistory_t{{datetag}}

并使用模板创建如下查询:


select '2014-01-01' as date, itemid, price

from orderhistory_t20140101


union all 


select '2014-01-02' as date, itemid, price

from orderhistory_t20140102


union all 


select '2014-01-03' as date, itemid, price

from orderhistory_t20140103

如何遍历 Golang 的切片并将它们放入 sql 模板中?


白衣非少年
浏览 147回答 1
1回答
随时随地看视频慕课网APP

相关分类

Go
我要回答