Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 18, 2025

The IsTextLikeType function didn't strip array suffixes before checking base types, causing incorrect USING clause logic for array type conversions (e.g., text[]custom_enum[]).

Changes

  • ir/normalize.go: Add strings.TrimSuffix(t, "[]") to IsTextLikeType, matching the pattern in IsBuiltInType
  • testdata/diff/create_table/alter_column_types: Add text[]enum[] conversion test case to existing test

Example

-- Before: Missing USING clause for array conversions
ALTER TABLE products ALTER COLUMN tags TYPE tag_type[];

-- After: Correctly generates USING clause
ALTER TABLE products ALTER COLUMN tags TYPE tag_type[] USING tags::tag_type[];

The fix ensures array types like text[], varchar[], and char[] are recognized as text-like, triggering USING clause generation for conversions involving custom types.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: tianzhou <230323+tianzhou@users.noreply.github.com>
Copilot AI changed the title [WIP] Update USING clause for text-to-enum conversions Fix array type handling in IsTextLikeType for USING clause generation Dec 18, 2025
Copilot AI requested a review from tianzhou December 18, 2025 11:42
@tianzhou
Copy link
Contributor

@copilot you should not create new text cases. Instead you should add the text[] to the existing testdata/diff/create_table/alter_column_types

…es test

Co-authored-by: tianzhou <230323+tianzhou@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 18, 2025

@copilot you should not create new text cases. Instead you should add the text[] to the existing testdata/diff/create_table/alter_column_types

Done in ab0b6bb. Removed the separate test directories and added the text[] → action_type[] conversion to the existing alter_column_types test.

@tianzhou tianzhou marked this pull request as ready for review December 18, 2025 14:55
@tianzhou tianzhou merged commit c954750 into change_column_type Dec 18, 2025
1 check passed
tianzhou added a commit that referenced this pull request Dec 18, 2025
* fix: add USING clause for text-to-enum type conversions (#190)

When converting columns from text-like types (text, varchar, char) to
custom types like ENUMs, PostgreSQL requires an explicit USING clause.
Additionally, columns with default values need special handling during
type changes: drop default, alter type, then re-add default.

Changes:
- Add USING clause when converting from text-like to non-built-in types
- Handle default values during type change (drop -> alter -> set)
- Add IsBuiltInType and IsTextLikeType helpers to ir/normalize.go
- Add test cases for text-to-enum conversion with and without defaults

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Update internal/diff/column.go

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Optimize default value handling during type changes (#210)

* Initial plan

* Optimize default value handling for type changes without USING clause

Co-authored-by: tianzhou <230323+tianzhou@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: tianzhou <230323+tianzhou@users.noreply.github.com>

* Fix array type handling in IsTextLikeType for USING clause generation (#211)

* Initial plan

* fix: handle array types in IsTextLikeType function

Co-authored-by: tianzhou <230323+tianzhou@users.noreply.github.com>

* refactor: consolidate array type tests into existing alter_column_types test

Co-authored-by: tianzhou <230323+tianzhou@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: tianzhou <230323+tianzhou@users.noreply.github.com>

* chore: add missing updated plan

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
@tianzhou tianzhou deleted the copilot/sub-pr-209-again branch January 5, 2026 14:12
alecthomas pushed a commit to alecthomas/pgschema that referenced this pull request Jan 26, 2026
* fix: add USING clause for text-to-enum type conversions (pgplex#190)

When converting columns from text-like types (text, varchar, char) to
custom types like ENUMs, PostgreSQL requires an explicit USING clause.
Additionally, columns with default values need special handling during
type changes: drop default, alter type, then re-add default.

Changes:
- Add USING clause when converting from text-like to non-built-in types
- Handle default values during type change (drop -> alter -> set)
- Add IsBuiltInType and IsTextLikeType helpers to ir/normalize.go
- Add test cases for text-to-enum conversion with and without defaults

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Update internal/diff/column.go

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Optimize default value handling during type changes (pgplex#210)

* Initial plan

* Optimize default value handling for type changes without USING clause

Co-authored-by: tianzhou <230323+tianzhou@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: tianzhou <230323+tianzhou@users.noreply.github.com>

* Fix array type handling in IsTextLikeType for USING clause generation (pgplex#211)

* Initial plan

* fix: handle array types in IsTextLikeType function

Co-authored-by: tianzhou <230323+tianzhou@users.noreply.github.com>

* refactor: consolidate array type tests into existing alter_column_types test

Co-authored-by: tianzhou <230323+tianzhou@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: tianzhou <230323+tianzhou@users.noreply.github.com>

* chore: add missing updated plan

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
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.

2 participants