Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use expression deparsing to convert column DEFAULT expressions #535

Merged
merged 2 commits into from
Dec 16, 2024

Conversation

andrew-farries
Copy link
Collaborator

Deparse column DEFAULT expressions using pg_query_go.DeparseExpr to allow conversion of arbitrary expressions in column DEFAULTs to pgroll migrations.

Replace manual deparsing of literal nodes with use of DeparseExpr to allow deparsing of any column DEFAULT expression.

Update test cases:

  • ALTER TABLE foo ALTER COLUMN bar SET DEFAULT now() is now representable as an OpAlterColumn; no need to fall back to raw SQL anymore.
  • Add a new testcase: ALTER TABLE foo ALTER COLUMN bar SET DEFAULT (first_name || ' ' || last_name) to demonstrate conversion of a column DEFAULT using a more complex expression.

Part of #504

Use `DeparseExpr` to convert the default expression to a string. This
allows us to handle more complex default expressions than just literals.
@andrew-farries andrew-farries force-pushed the deparse-default-expression-nodes branch from 93f7291 to 15c3f2e Compare December 16, 2024 09:12
@andrew-farries andrew-farries marked this pull request as ready for review December 16, 2024 09:19
@andrew-farries andrew-farries merged commit 694d935 into main Dec 16, 2024
28 checks passed
@andrew-farries andrew-farries deleted the deparse-default-expression-nodes branch December 16, 2024 12:33
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