alter() on PostgreSQL cannot change an attribute: MODIFY is a syntax error, and a comment change is ignored
維護者通常 6 天內回覆
評估
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 新手友好度
- 62/100
研究方向
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 內容生成。
描述
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'sMODIFY <column definition>. PostgreSQL needsALTER COLUMN ... TYPE ...,SET/DROP NOT NULLandSET/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, andalter()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 ..., withUSINGwhere 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, sodescribe()still round-trips.
Repositioning a column has no PostgreSQL equivalent; it is already skipped there (supports_column_position).
- 主要語言
- Python
- 星號
- 198
- 分支
- 103
- 平均合併
- 6 天 1 小時
- 30 天內合併 PR
- 10
環境準備
- 提供 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
datajoint/datajoint-python 的其他 Issue
-
bug
難度 2/5 1-3 小時 新手友好度 78/100
datajoint/datajoint-python#1703 ·
維護者通常 6 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 78/100
datajoint/datajoint-python#1702 ·
維護者通常 6 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 78/100
datajoint/datajoint-python#1701 ·
維護者通常 6 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 74/100
datajoint/datajoint-python#1691 ·
維護者通常 6 天內回覆
-
dependencies needs-discussion
難度 2/5 1-3 小時 新手友好度 68/100
datajoint/datajoint-python#1687 ·
維護者通常 6 天內回覆
查看 datajoint/datajoint-python 的全部 Issue
相似的 Issue
-
needs-triage
難度 1/5 1-3 小時 新手友好度 85/100
gke-labs/kube-agents#6620 ·
維護者通常 1 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 75/100
open-webui/open-webui#34719 · 2 則留言 ·
維護者通常 1 天內回覆
-
cognition
難度 2/5 1-3 小時 新手友好度 82/100
維護者通常 1 天內回覆
-
One non-object JSON record makes the session catalog exit可能已有人在做 @he-yufeng 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 68/100
維護者通常 1 天內回覆
-
難度 1/5 1 小時以內 新手友好度 78/100
collabnix/awesome-mcp-lists#433 ·
維護者通常 4 天內回覆