Index on a JSON path fails to declare on PostgreSQL

未關閉
#1,672 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 6 天內回覆

@mayuriphad 已經在處理了。

開始於 2026年11月17日。

  • #1684 來自 @mayuriphad —— 未關閉

評估

難度
3/5
預估耗時
1-2 天
新手友好度
55/100
Issue 類型
缺陷
描述清晰度
基本清楚
活躍度
活躍
技術堆疊
mysql, postgresql, python
領域
databases

研究方向

The index is parsed from the compiled definition by the regex in src/datajoint/declare.py around lines 616-627, which stops at the first closing parenthesis. The per-index statement is built in create_index_ddl in src/datajoint/adapters/base.py around lines 696-704. Start by reproducing the data.size:integer JSON-path index declaration on PostgreSQL and reading the generated CREATE INDEX text. Done means the table declares on both PostgreSQL and MySQL, with a test covering the JSON-path index on each backend.

由索引模型根據 Issue 內容生成。

描述

bug

Bug

Declaring an index on a JSON path works on MySQL but fails on PostgreSQL with a syntax error.

@schema
class Indexed(dj.Manual):
    definition = """
    item_id : int32
    ---
    data = null : json
    index(data.size:integer)
    """

On PostgreSQL, declaring the table fails with a syntax error in the generated statement, which starts with:

CREATE INDEX "idx_indexed_((jsonb_extract_path_text("dat" ...

Cause

PostgreSQL has no inline INDEX in CREATE TABLE, so declare() turns each index into a separate CREATE INDEX statement:

  • declare.py L616–627 parses the compiled index with r"(unique\s+)?index\s*\(([^)]+)\)". [^)]+ stops at the first ), so a parenthesized expression is cut short. The pieces are then treated as plain column names.
  • adapters/base.py L696–704 (create_index_ddl) quotes each "column" as an identifier and builds the index name from the column text. For an expression, both the name and the column list end up as invalid SQL.

Suggested fix

Pass the index items to create_index_ddl as structured data (column name or expression) instead of re-parsing the MySQL-style text:

  • Quote plain columns.
  • Emit expressions in their own parentheses.
  • Derive the index name from a sanitized or hashed form of the items, kept within PostgreSQL's 63-character limit.

A test declaring a JSON-path index on both backends would cover it.

主要語言
Python
星號
198
分支
103
平均合併
6 天 1 小時
30 天內合併 PR
10

環境準備

  • 提供 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 閱讀貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

datajoint/datajoint-python 的其他 Issue

查看 datajoint/datajoint-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。