postgresql – 在postgres中的“$1”或附近的golang语法错误
发布时间:2020-12-13 16:01:46 所属栏目:百科 来源:网络整理
导读:我正在尝试使用sql模块执行查询. var from string = "2015-03-01 00:00:00" rows,err := db.Query("select time,val from table where " + "time = extract(epoch from timestamp with time zone $1)::int4 " + "and time extract(epoch from timestamp with
我正在尝试使用sql模块执行查询.
var from string = "2015-03-01 00:00:00" rows,err := db.Query("select time,val from table where " + "time >= extract(epoch from timestamp with time zone $1)::int4 " + "and time < extract(epoch from timestamp with time zone '2015-03-01 00:15:10')::int4 " + "order by time asc",from) 但是我得到了错误 pq: syntax error at or near "$1" 如果我直接输入epoch值,那么查询将起作用,并且当我在没有任何变量的情况下尝试它时查询工作,即查询硬编码. 解决方法
你的价格是1美元和?
它抱怨$1语法无效的原因是因为类型转换.这样说: rows,val from table where " + "time >= extract(epoch from $1::timestamp with time zone)::int4 " + "and time < extract(epoch from timestamp with time zone '2015-03-01 00:15:10')::int4 " + "order by time asc",from) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |