Index on a JSON path fails to declare on PostgreSQL

Abierto
#1,672 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 6 días

@mayuriphad ya está trabajando en esto.

Desde el 17/11/2026.

  • #1684 de @mayuriphad — abierto

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
55/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
mysql, postgresql, python
Área
databases

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Python
Estrellas
198
Forks
103
Merge medio
6 d 1 h
PR fusionados (30 d)
10

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de datajoint/datajoint-python

Todos los issues de datajoint/datajoint-python

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.