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

オープン
#1,625 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 6 日以内に返信

@dimitri-yatsenko がすでに取り組んでいます。

2026年10月18日 から。

  • #1639 @dimitri-yatsenko による — オープン

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
62/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
postgresql, python, sql
領域
backend, database

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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).

主要言語
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 を短くまとめたダイジェスト。