Skip to content

db2: createTable and sync never apply column comments #18289

Open

Description

@WikiRik

Issue

On db2, queryInterface.createTable() never applies column comments. Db2QueryGenerator#createTableQuery emits them as an inert SQL line comment appended to the statement:

CREATE TABLE IF NOT EXISTS "myTable" ("id" INTEGER, "name" VARCHAR(255)); -- 'Te''st', TableName = "myTable", ColumnName = "id";

Everything after -- is a comment to db2, so the text is parsed and discarded. Nothing reaches SYSCAT.COLUMNS.REMARKS.

The same is true of Model.sync(), which goes through the same code path.

Context

#18288 fixed the equivalent problem for addColumn and changeColumn. Those previously emitted an inline COMMENT '…' clause that db2 rejects outright (SQL0104N, SQLSTATE=42601); they now generate a standalone statement via Db2QueryGenerator#commentOnColumnQuery() and execute it as a follow-up query in Db2QueryInterface, which is verified to persist the comment.

createTableQuery was deliberately left out of that PR — its output is byte-identical before and after, and there is a test pinning it — because fixing it is a larger change than the escaping work that PR was scoped to.

Why it needs its own change

db2's Query calls connection.prepare(sql), and node-ibm_db's prepare executes only the first statement (ibmdb/node-ibm_db#319). So appending ; COMMENT ON COLUMN … to the CREATE TABLE string will not work — the extra statements are silently discarded, which is exactly the failure mode #18288 had to design around.

The fix therefore has to issue the comment statements as separate queries after the CREATE TABLE, in the same place createTable runs. Db2QueryInterface#addColumn / #changeColumn in #18288 are the pattern to follow, and commentOnColumnQuery() already exists to generate the statement.

Points to settle when implementing:

  • Where the comments are collected. createTableQuery currently formats them into the SQL string; they would need to be available to the QueryInterface instead.
  • Transactionality. createTable plus N comment statements can partially fail. fix(dialects): escape identifiers in changeColumn and renameColumn #18288 deliberately does not open an implicit transaction — it passes options through so the statements join the caller's transaction if there is one, consistent with dropAllSchemas and addConstraint. The same choice probably applies here, but with N statements rather than one it is worth revisiting.
  • Model.sync() should be covered by the same fix, and is the more common way users hit this.

Verification

Assert against the catalog rather than the generated SQL — valid-looking SQL that silently does nothing is precisely the failure this class of bug produces:

SELECT REMARKS FROM SYSCAT.COLUMNS WHERE TABSCHEMA = ? AND TABNAME = ? AND COLNAME = ?

yarn start-db2-latest brings up a suitable instance.


Created by Opus 5 with Claude Code, supervised by @WikiRik.

Activity

  1. self-assigned this
    on Jul 29, 2026
  2. added
    type: bug
    dialect: db2
    on Jul 29, 2026
  3. added
    pending-approval
    on Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

dialect: db2pending-approvaltype: bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions