Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PostgreSQL中Python映射运算符的等价物_Sql_Postgresql - Fatal编程技术网

PostgreSQL中Python映射运算符的等价物

PostgreSQL中Python映射运算符的等价物,sql,postgresql,Sql,Postgresql,我在PostgreSQL数据库中有这样一个表 ID, Name, scores. 10, abc,{23,19,34} 11, def, {2333,233,24} 12, ghi, {321,34} 13,hio,{} 上述数据模型中的分数是一个数组或数字列表 现在我们必须找到所有学生,他们的分数是19除以10。我怎样才能做到这一点 我试过了,但没用 SELECT * FROM students where 19 = ANY(scores)/10 像这样的东西很管用。但是我们需要一个更好的

我在PostgreSQL数据库中有这样一个表

ID, Name, scores.
10, abc,{23,19,34}
11, def, {2333,233,24}
12, ghi, {321,34}
13,hio,{}
上述数据模型中的分数是一个数组或数字列表

现在我们必须找到所有学生,他们的分数是19除以10。我怎样才能做到这一点

我试过了,但没用

SELECT * FROM students where 19 = ANY(scores)/10
像这样的东西很管用。但是我们需要一个更好的解决方案,使用一个倒排索引,因为行数可能在数百万左右

SELECT * FROM students where 190 <= ANY(scores) < 200

在您的数据示例中,没有满足某个值除以10等于19的条件的记录。但我知道你们确定你们的条件,数组中的一个数除以10应该等于19。不是全部或什么的总和

首先,你们在分数栏上有gin索引吗? 第二,分数数组中的单个数字是否会大于整数限制?如果没有,bigint只会减慢查询速度。 考虑BigIt问题,如果您必须拥有它,则从下面的查询

删除:BigIt:
SELECT * FROM students where 
scores&&array[190,191,192,193,194,195,196,197,198,199]::bigint
这很难看,但可能比从数组中提取所有数字的任何尝试都要快,首先将它们除以10,然后再与19进行比较。
如果只搜索分数除以10后等于19的数字,只需使用Abelisto方法,但在插入时,它将是一个杀手,因为保存数以百万计的行和长数组的函数索引会很慢。

分数的数据类型是什么?分数是一个数字列表。数据库中的分数列是什么数据类型?bigint[]-这是一个大整数数组