Skip to content

Support Default on Google Cloud Spanner #918

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

Open
zaitera opened this issue Apr 14, 2023 · 2 comments · May be fixed by #1197
Open

Support Default on Google Cloud Spanner #918

zaitera opened this issue Apr 14, 2023 · 2 comments · May be fixed by #1197

Comments

@zaitera
Copy link

zaitera commented Apr 14, 2023

Is your feature request related to a problem? Please describe.
We can't run migrations with DEFAULT (for example adding column and setting a default value for the existing record)

Describe the solution you'd like
Being able to execute statements like the following:
ALTER TABLE t1 ADD COLUMN c1 STRING(MAX) DEFAULT ('');
Google cloud spanner already supports this syntax, and I've tried it on the cloud console

Describe alternatives you've considered
Disabling CleanStatements makes it possible to execute that statement, but then we lose the option to have comments or multiple statements in the migration file

Additional context
Add any other context or screenshots about the feature request here.

@IDispose
Copy link

This will be more useful if the following is also supported
ALTER TABLE t1 ADD COLUMN c1 STRING(MAX) NOT NULL DEFAULT ('')

Currently this throws an error saying Cannot add non-null columns to an existing table

@IDispose
Copy link

IDispose commented Feb 6, 2024

For anyone looking for a workaround, this works.

ALTER TABLE t1 ADD COLUMN c1 STRING(MAX) DEFAULT ('');
ALTER TABLE t1 ALTER COLUMN c1 STRING(MAX) NOT NULL DEFAULT ('')

put those together and your table DDL will look like this

CREATE TABLE 
    t 1 (
        -- other columns
        c1 STRING(MAX) NOT NULL DEFAULT ('')
    )

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 a pull request may close this issue.

2 participants