Index on a JSON path fails to declare on PostgreSQL

オープン
#1,672 コメント 0 件 リアクション 0 件 担当者 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時間
マージ済み PR(30日)
10

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

datajoint/datajoint-python のほかの issue

datajoint/datajoint-python の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。