Index on a JSON path fails to declare on PostgreSQL

Offen
#1,672 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 6 Tagen

@mayuriphad arbeitet bereits daran.

Seit 17.11.2026.

  • #1684 von @mayuriphad — offen

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
55/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Aktiv
Tech-Stack
mysql, postgresql, python
Bereich
databases

Rechercherichtung

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.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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.

Vorherrschende Sprache
Python
Sterne
198
Forks
103
Ø Merge
6 T. 1 Std.
Gemergte PRs (30 T.)
10

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus datajoint/datajoint-python

Alle Issues in datajoint/datajoint-python

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.