Skip to content

sql-839: Report SQL string 'NULL' for table column defaults in mz_columns again - #40316

Merged
SangJunBak merged 4 commits into
mainfrom
jun/sql-839-terraform-apply-drops-and-recreates-tables-after-the
Oct 29, 2026
Merged

SangJunBak merged 4 commits into
mainfrom
jun/sql-839-terraform-apply-drops-and-recreates-tables-after-the

Conversation

@SangJunBak

@SangJunBak SangJunBak commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Before, tables whose columns' defaults were undefined we'd store their mz_columns default value as the SQL string 'NULL' but would store it as NULL for other relation objects. In #40001 , we decided to unify the behavior and store it as NULL for tables too. However, this created a regression in our terraform provider where it'd drop and create tables with no defaults on their columns because of a schema mismatch. Thus we change it back to the SQL string NULL.

Motivation

Closes: SQL-839

Verification

We still get pg compatibility by just changing the definition of the information_schema / pg views. This is why we don't need to update any of the SLT tests related to those views.

SangJunBak and others added 3 commits October 28, 2026 16:52
mz_columns.default reads as the string NULL for a table column without a
default, as it did in every release through v26.48. #40001 made it SQL
NULL, which the Terraform provider (every release through v0.11.12)
compares against its declared default of "NULL": it then replaces the
table on every apply and drops its rows (SQL-839).

Builtin tables read the string too, so the contract holds for every table
and not only for user tables.

The PostgreSQL-compatible views keep the behavior #40001 gave them by
mapping the string to no default: pg_attribute.atthasdef is false,
pg_attrdef has no row and information_schema.columns.column_default is
NULL for such a column.

Closes: SQL-839

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
A table column without a default reads as the string NULL in mz_columns
and as no default in pg_attribute, pg_attrdef and information_schema
(SQL-839).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@SangJunBak
SangJunBak requested review from a team as code owners October 28, 2026 20:56
@linear-code

linear-code Bot commented Oct 28, 2026

Copy link
Copy Markdown

SQL-839

@ggevay ggevay left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the quick fix!

Looks good. Two nits inline.

item_columns_initial_mv 2 b true text <null> text -1
item_columns_initial_mv 3 c1 true numeric <null> numeric -1
item_columns_initial_table 1 a false integer <null> int4 -1
item_columns_initial_table 1 a false integer NULL int4 -1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The two version branches now expect the same rows, and the comment above them ("From 26.49 on ... no default reads as SQL NULL") no longer holds. The guard and comment can go, leaving one query.

Comment thread src/catalog-decode/src/create_sql.rs Outdated
.map_or(serde_json::Value::Null, |expr| {
json!(expr.to_ast_string_stable())
})
// A column without a default reads as the string NULL, see the

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth saying why here, so the next cleanup doesn't undo it: clients compare against this string, and the Terraform provider replaces a table whose column default reads as SQL NULL (SQL-839). Maybe also TODO(DEX-197): switch to SQL NULL once released providers read it as no default.

- Say at the decision point why a missing default reads as the string NULL
- Drop the 26.49 version guard in
the item_columns platform check, since both sides now expect the same rows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@SangJunBak
SangJunBak force-pushed the jun/sql-839-terraform-apply-drops-and-recreates-tables-after-the branch from 8d8f551 to 4e7e4aa Compare October 29, 2026 13:52
@SangJunBak
SangJunBak merged commit 077d0f3 into main Oct 29, 2026
87 checks passed
@SangJunBak
SangJunBak deleted the jun/sql-839-terraform-apply-drops-and-recreates-tables-after-the branch October 29, 2026 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants