alter() on PostgreSQL cannot change an attribute: MODIFY is a syntax error, and a comment change is ignored

Aberta
#1,625 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 6 dias

@dimitri-yatsenko já está trabalhando nisso.

Desde 18/10/2026.

  • #1639 de @dimitri-yatsenko — aberto

Avaliação

Dificuldade
4/5
Tempo estimado
3-5 dias
Facilidade para iniciantes
62/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
postgresql, python, sql
Domínio
backend, database

Direção de pesquisa

Inspect _make_attribute_alter in declare.py and run the supplied reproduction against PostgreSQL and MySQL to compare the generated SQL. Follow the existing type, nullability, default, rename, and comment comparison paths; PostgreSQL handling must emit backend-specific statements while preserving the core-type marker. Done means all listed PostgreSQL alterations succeed, comment-only changes are applied, and incompatible casts produce a clear error.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

bug

Summary

On PostgreSQL, Table.alter() can add, drop and rename attributes, but it cannot change one:

  • Changing an attribute's type, nullability or default raises a syntax error. _make_attribute_alter (declare.py) always emits MySQL's MODIFY <column definition>. PostgreSQL needs ALTER COLUMN ... TYPE ..., SET/DROP NOT NULL and SET/DROP DEFAULT.
  • Changing only an attribute's comment does nothing, silently. On PostgreSQL the comment is not part of the column definition: it is applied with COMMENT ON COLUMN. So a comment-only change compares as unchanged, and alter() reports nothing to alter.

MySQL handles all five changes.

Reproduction

DataJoint master, PostgreSQL 15 and MySQL 8.0:

import datajoint as dj

schema = dj.Schema("scratch_alter_pg")


@schema
class Measurement(dj.Manual):
    definition = """
    measurement_id : int32
    ---
    value : float32   # the value
    """


Measurement.definition = """
measurement_id : int32
---
value : float64   # the value
"""
Measurement.alter(prompt=False)
New definition of value MySQL PostgreSQL
value : float64 # the value altered QuerySyntaxError: syntax error at or near "MODIFY" (MODIFY "value" double precision NOT NULL)
value = null : float32 # the value altered same error (MODIFY "value" real DEFAULT NULL)
value = 1.5 : float32 # the value altered same error (MODIFY "value" real NOT NULL DEFAULT '1.5')
reading : float32 # the value {value} (rename) altered altered
value : float32 # another comment altered no change, no message

Expected behavior

On PostgreSQL, alter() makes the same changes it makes on MySQL:

  • a type change becomes ALTER COLUMN ... TYPE ..., with USING where the cast needs it, or a clear error when the backend cannot convert;
  • a nullability change becomes SET/DROP NOT NULL;
  • a default change becomes SET/DROP DEFAULT;
  • a comment change becomes COMMENT ON COLUMN, with the core-type marker kept, so describe() still round-trips.

Repositioning a column has no PostgreSQL equivalent; it is already skipped there (supports_column_position).

Linguagem predominante
Python
Estrelas
198
Forks
103
Merge médio
6d 1h
PRs com merge (30d)
10

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de datajoint/datajoint-python

Todas as issues de datajoint/datajoint-python

Issues semelhantes

Mais issues de Python

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.