在postgresql-simple中使用cubes导致“多行模板语法错误”的错误

问题描述 投票:0回答:1

你打算如何将

cube
s
postgresql-simple
一起使用?

此刻,我正在做类似的事情

query conn "SELECT thing FROM table WHERE coord <@ cube('?, ?') ORDER BY cube_distance(coord, cube('?')) ASC" 
      (In [a, b, c], In [d, e, f], In [g, h, i])

效果很好,但感觉像是对

In
的误用。在
executeMany
的情况下它也会失败。例如

executeMany conn "INSERT INTO table(thing, coord) VALUES(?, cube('?'))" lst

其中

lst :: [(String, In [Float])]
syntax error in multi-row template
失败。等效,但效率较低

mapM_ (execute conn "INSERT INTO table(thing, coord) VALUES(?, cube('?'))") lst

工作正常,所以我假设这与

executeMany
组织插入参数的方式有关。

但是,文档没有提到

Cube
类型,我找不到它的使用示例,所以我不太确定我 supposed 做什么。

postgresql haskell cube
1个回答
0
投票

你可以使用我写的这个迷你图书馆。一旦你包括它,你就可以做

execute "INSERT INTO table(cube_field, name) VALUES(?, ?) RETURNING id" (Cube [[1, 2, 3]], "Testing")

更重要的是,

executeMany "INSERT INTO table(cube_field, name) VALUES(?, ?) RETURNING id"
            [(Cube [[1, 2]], "One"), (Cube [[3, 4]], "Two"), (Cube [[5, 6]], "Three")]

没有

fromField
实例,所以此时不能选择
Cube
s。我不会添加它,因为它看起来很重要,而且我的用例不需要它,但是绝对欢迎补丁

© www.soinside.com 2019 - 2024. All rights reserved.