copy_from_query drops headers if any postgis NOTICE/LOCATION messages produced

未关闭
#1,264 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
postgresql, python
领域
databases

调研方向

从 Connection.copy_from_query 开始,在启用 PostGIS NOTICE/LOCATION 消息的情况下,针对 PostgreSQL 重现所提供的 COPY 查询。跟踪这些消息如何与 COPY 输出一起被处理;当产生此类通知时,返回的数据仍保留其 CSV 标头,即表示完成。

由索引模型根据 Issue 内容生成。

描述

when using Connection.copy_from_query I had a statement which eventually resolved to something like:

COPY (
    select 1
    from field_year_crop_variety_layer fycvl
    cross join filters
    join field_meta fm on
        fm.field_id = fycvl.field_id and
        (filters.filter_geometry is null or st_intersects(filters.filter_geometry, fm.centroid))
    order by fycvl.field_id, fycvl.harvest_year, fycvl.layer_id, fycvl.crop, fycvl.variety
    limit '100000'::int
) TO STDOUT (FORMAT 'csv', HEADER True)

where filter_geometry is a geometry, and fm.centroid is a geography.

and no matter what I did asyncpg would not return the headers. It wasn't until I broke it down and ran it from psql that I noticed the output:

field_id,harvest_year,layer_id,crop,variety,is_precision_data,date_period,avg_date,data_is_missing,missing_data_message,crop_variety_layer_area_m2,geometry,computed_at
NOTICE:  00000: Coordinate values were coerced into range [-180 -90, 180 90] for GEOGRAPHY
LOCATION:  geography_from_geometry, geography_inout.c:510
NOTICE:  00000: Coordinate values were coerced into range [-180 -90, 180 90] for GEOGRAPHY
LOCATION:  geography_from_geometry, geography_inout.c:510
143011,2017,0,corn,unknown,t,"[2017-04-25,2017-04-26)",2017-04-24,f,,7240.833,,1752130305.616610

sure enough, if I fixed the bug (casting fm.centroid to a geometry) the headers appeared. This seems like a bug in asyncpg when interpreting the data returned.

主要语言
Python
星标
8.1k
派生
469
平均合并
4 小时 42 分钟
30 天内合并 PR
6

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

MagicStack/asyncpg 的其他 Issue

查看 MagicStack/asyncpg 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。