提问人:vizyourdata 提问时间:11/10/2023 更新时间:11/10/2023 访问量:69
我的 SQL 编辑器和 Python psycopg2 查询之间的记录计数差异
Difference in record counts between my SQL editor and Python psycopg2 query
问:
我正在运行从 sql 编辑器复制到 python 的完全相同的 redshift 查询。在 python 中,我测试了来自 pandas.read_sql 的计数,并直接 psycopg2 cursor.execute 查询。在 SQL 编辑器方面,我已经测试了 dbeaver、beekeeper 和 mysqlworkbench 中的计数。我去除了所有联接,以简化查询,环境类型之间发生相同的差异。我已经检查了所有环境中的getdate(),并看到了相同的时间戳,以排除环境之间时区的任何差异。如果是几条记录,我可以将其归因于时间,但在 20 个月的窗口期内,它在 30-6k 范围内。我还应该检查什么?
简化查询:
select count(distinct u.customerid)
from users u
Python 设置:
conn = psycopg2.connect(f"dbname={DB} host={HOST} port={PORT}
user={USER} password={PWD}")
cursor = conn.cursor()
cursor.execute(''' select count(distinct u.customerid)
from users u
''')
result = cursor.fetchone()
print(result)
conn.close()
答: 暂无答案
评论
GETDATE()
EXPLAIN
DISTINCT
DISTINCT
select customerid