简体   繁体   English

simple_salesforce python:sf.instance.bulk.query 给出索引错误

[英]simple_salesforce python : sf.instance.bulk.query gives index error

So I am trying to query from the salesforce using the python simple_salesforce library: The query is a Select like shown below:因此,我尝试使用 python simple_salesforce 库从 salesforce 查询:查询是 Select,如下所示:

sf.bulk.instance.query("SELECT  field_1, field_2 from table__c WHERE name IN ('1', '2' ...2000 values)")

The tuple I pass has about 2000 values.我传递的元组有大约 2000 个值。 So when I try to use sf.query it is giving back 414 or the connection get aborted(sometimes it gives URI too long).因此,当我尝试使用 sf.query 时,它会返回 414 或连接被中止(有时它提供的 URI 太长)。 Then I tried to use the sf.bulk where I can go up to 1300 values, but after that it is giving index error: list index out of range .然后我尝试使用 sf.bulk 我可以 go 最多1300个值,但之后它给出index error: list index out of range This is raised from _get_batch_results .这是从_get_batch_results提出的。

For now I have split the tuple into parts and made multiple queries to sf.bulk query which I think is not efficient.现在,我已将元组拆分为多个部分并对 sf.bulk 查询进行了多次查询,我认为这效率不高。 Could anyone provide me a solution for this?任何人都可以为我提供解决方案吗?

Any help is appreciated!任何帮助表示赞赏!

You get this error because your query is too long and of course this is due to your very long WHERE... IN condition.您收到此错误是因为您的查询太长,当然这是由于您的WHERE... IN条件太长。

My suggestion is to throw the values you have in the IN in a temporary table a rewrite the query as a join between the two tables.我的建议是将IN中的值放入临时表中,并将查询重写为两个表之间的连接。

If you can create a second table, table__d , with the list of values, then your query can look like:如果您可以使用值列表创建第二个表table__d ,那么您的查询可能如下所示:

SELECT field_1, field_2 
  FROM table__c 
 WHERE name IN (SELECT name from table__d)

Alternatively you can split your query in 2 queries with 1000 values each, or even in smaller chunks.或者,您可以将查询拆分为 2 个查询,每个查询有 1000 个值,甚至可以分成更小的块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM