MagicStack / MagicStack/asyncpg

When using Redshift - PostgresSyntaxError: syntax error at or near "ORDER" - in query with no "ORDER"

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

还没有人认领这个 Issue。

主要语言
Python
星标
8.1k
派生
468
PR 合并指标
30 天内没有已合并 PR

描述

* **asyncpg version**: asyncpg==0.27.0.
* **PostgreSQL version**: PostgreSQL 8.0.2 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.4.2 20041017 (Red Hat 3.4.2-6.fc3), Redshift 1.0.46987.
* **Do you use a PostgreSQL SaaS? If so, which? Can you reproduce
the issue with a local PostgreSQL install?**: I am using Amazon Redshift. I could not reproduce the issue with `potgres:9.0` Docker image.
* **Python version**: Python 3.9.12.
* **Platform**: Windows 10 Pro, 22H2, 19045.2604.
* **Do you use pgbouncer?**: No.
* **Did you install asyncpg with pip?**: Yes.
* **If you built asyncpg locally, which version of Cython did you use?**: -
* **Can the issue be reproduced under both asyncio and
[uvloop](https://github.com/magicstack/uvloop)?**: Have not tried `uvloop`.

Running this snippet:

```python
options = ConnectionOptions()

sslctx = ssl.create_default_context(ssl.Purpose.SERVER_AUTH)
sslctx.check_hostname = False
sslctx.verify_mode = ssl.CERT_NONE

connection = await asyncpg.connect(options.dsn, ssl=sslctx)

try:
query = "select 'all' = any($1::text[])"
await connection.fetch(query, ["all"])

finally:
await connection.close()
```

I get this exception:

```python
asyncpg.exceptions.PostgresSyntaxError: syntax error at or near "ORDER"
```

I am wondering, where the "syntax error at or near "ORDER" comes from, as there is no "ORDER" in the original query.

If `asyncpg` does not rewrite queries in any way, and the query passed to `fetch` is forwarded to the database without modification (https://github.com/MagicStack/asyncpg/issues/434#issuecomment-910474719, https://github.com/MagicStack/asyncpg/discussions/859#discussioncomment-1742492) - where does the "ORDER" come from?

Can this issue be worked around, or I should abandon `asyncpg` as a Redshift client? I do understand that Redshift is not officially supported, but this client is very good otherwise.

I was not able to reproduce the error with the `postgres:9.0` instance (the oldest I was able to find quickly). The same (except `ssl=False`) snippet works without errors.

贡献指南

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

从这里开始

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

调研方向

Start with the connection.fetch entry point and the reproduced query `select 'all' = any($1::text[])`, then compare its behavior on Redshift with the reported PostgreSQL Docker image. Determine whether the syntax error originates in asyncpg or Redshift, and document a confirmed workaround or the compatibility limitation.

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

评估

技术栈
postgresql, python
领域
databases
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
需要澄清
新手友好度
25/100

把新 issue 发到你的邮箱

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