0

我已经使用 python 设置了一个 AWS Lambda 函数以从 CSV 中提取请求,然后根据此请求查询 AWS 无服务器 Aurora PostgreSQL 数据库。该函数在请求小于 1K 时起作用,但由于数据 API 中的硬限制而出现错误。一旦达到此限制,我试图找出一种方法将查询分解为更小的查询,但不确定如何在 python 中执行此操作。有人可以建议一种将请求分解成更小块的方法,这样我就不会达到数据 API 限制吗?

使用的代码片段:

#Set Database connection params
engine = wr.data_api.rds.connect( resource_arn = resource_arn, database=database_name, secret_arn=secret_arn)

#read in s3 csv and select ids
read_df = wr.s3.read_csv(path=s3_path_in)
requested_ids = read_df["ids"]
in_ID = requested_ids.tolist()
in_query= str(tuple(in_ID))

#query postgres
query_id = """
select c.*
from table1 b
INNER JOIN table2 c on b.id = c.id
where b.id in %s
""" % in_query

out_ids = wr.data_api.rds.read_sql_query(query_id, engine) 
4

1 回答 1

0

我能想到的一种方法是使用LIMIT <row_count>postgres SQL 的子句并将其动态传递row_count给您的查询。

select c.*
from table1 b
INNER JOIN table2 c on b.id = c.id
where b.id in <>
order by <primary_key>
limit 999

PostgreSQL 限制

于 2021-11-03T18:42:29.637 回答