是否可以循环查询以便如果(例如)找到500,000行,它将返回前10,000个的结果,然后再次重新运行查询?
所以,我想要做的是运行查询并构建一个数组,如下所示:
$result = pg_query("SELECT * FROM myTable");
$i = 0;
while($row = pg_fetch_array($result) ) {
$myArray[$i]['id'] = $row['id'];
$myArray[$i]['name'] = $row['name'];
$i++;
}
Run Code Online (Sandbox Code Playgroud)
但是,我知道会有几十万行,所以我想分批完成10,000个等级... 1- 9,999然后10,000 - 10,999等...原因是因为我一直收到这个错误:
Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 3 bytes)
Run Code Online (Sandbox Code Playgroud)
顺便说一句,顺便说一句,我不明白3个字节如何耗尽512M ...所以,如果那是我可以改变的东西,那就太好了,尽管如此,批量做这个仍然可能更好?
以下函数会一直返回此错误消息.我认为也许double_precision字段类型是造成这种情况的原因,我试图使用CAST,但要么就是这样,要么我做得不对......帮忙?
这是错误:
ERROR: input is out of range
CONTEXT: PL/pgSQL function "calculate_distance" line 7 at RETURN
********** Error **********
ERROR: input is out of range
SQL state: 22003
Context: PL/pgSQL function "calculate_distance" line 7 at RETURN
Run Code Online (Sandbox Code Playgroud)
这是功能:
CREATE OR REPLACE FUNCTION calculate_distance(character varying,
double precision, double precision,
double precision, double precision)
RETURNS double precision AS
$BODY$
DECLARE earth_radius double precision;
BEGIN
earth_radius := 3959.0;
RETURN earth_radius * acos(sin($2 / 57.2958) *
sin($4 / 57.2958) + cos($2/ 57.2958) * cos($4 / …Run Code Online (Sandbox Code Playgroud)