如何将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类型,我也找不到它的使用示例,所以我不太确定我应该做什么。
发布于 2015-07-08 00:28:38
你可以使用我写的这个迷你图书馆。一旦你把它包括进去,你就能做到
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实例,因此此时不能选择Cubes。我不会添加这个,因为它看起来并不简单,而且我不需要它作为我的用例,而是补丁绝对是欢迎的。
https://stackoverflow.com/questions/31226073
复制相似问题