我有一个postgesql表test_1
,如下所示:
|| ID || container_id || product_id ||
-----------------------------------------------------------------------------
|| 1 || 1 || 1 ||
-----------------------------------------------------------------------------
|| 2 || 1 || 2 ||
-----------------------------------------------------------------------------
|| 3 || 2 || 1 ||
-----------------------------------------------------------------------------
|| 4 || 2 || 2 ||
-----------------------------------------------------------------------------
我需要选择查询:
select * from test_1 where (container_id,product_id) in ((1,1),(1,2),(2,1));
这将返回ID为1到3的所有行。
是否有postgREST操作符可以选择所需的查询?
到目前为止我的网址:
http://localhost:8080/test_1?&product_id=in.(1,2)&container_id=in.(1,2)
这显然会返回所有值,因为这是不正确的。
从PostgREST版本10开始,没有任何操作符可以直接执行该查询。另一种选择是使用OR
:进行过滤
WHERE (product_id = 1 AND container_id = 1) OR
(product_id = 1 AND container_id = 2) OR
(product_id = 2 AND container_id = 1)
在PostgREST中,即:
http://localhost:3000/test_1?or=(and(product_id.eq.1,container_id.eq.1),and(product_id.eq.1,container_id.eq.2),and(product_id.eq.2,container_id.eq.1))
它给出了相同的结果,尽管在这种情况下语法更加详细(但不确定性能差异(。