对于上下文,我想查询以下内容:
select point '(1,1)' <@ box '((0,0),(2,2))';
我试过这样的事情:
CREATE TABLE tbl (latlng POINT NOT NULL);
box = [[22.268764039073968, -140.09765625000003], [61.438767493682825, -56.42578125000001]]
await pool.fetch(f'SELECT * FROM tbl WHERE latlng <@ $1;', box)
然后我尝试了这个:
from asyncpg.types import Point, Box
v = [[22.268764039073968,-140.09765625000003],[61.438767493682825,-56.42578125000001]]
box = Box(Point(v[0][0], v[0][1]), Point(v[1][0], v[1][1]))
await pool.fetch(f'SELECT * FROM tbl WHERE latlng <@ $1;', box)
两次尝试都会导致错误:
asyncpg.exceptions.AmbiguousFunctionError: operator is not unique: point <@ unknown
HINT: Could not choose a best candidate operator. You might need to add explicit type casts.
我猜我必须手动让 asyncpg 为此参数使用box_encode()(因为任何表定义都没有暗示它),但是我如何告诉 asyncpg 这样做呢?