-
Notifications
You must be signed in to change notification settings - Fork 73
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
Support for drop default on a column #450
Comments
This feels like something we want to add to We already allow setting the value of
From https://www.postgresql.org/docs/current/ddl-alter.html#DDL-ALTER-COLUMN-DEFAULT |
Yes, this belongs on I think we could handle this by distinguishing the case where |
So I realised while implementing this that we already support it. If we set the default value of a column to the string pgroll/pkg/migrations/op_set_default_test.go Line 222 in 96e50f9
Is this enough? Maybe we should just update the docs and add an example? |
The following statements look to have slightly different effects: alter table products alter column name set default NULL results in a column that looks like this:
whereas: alter table products alter column name drop default produces a column like this:
i.e Postgres catalogs record a default of "operations": [
{
"alter_column": {
"table": "products",
"column": "name",
"default": "NULL"
}
}
] from: "operations": [
{
"alter_column": {
"table": "products",
"column": "name",
"default": null
}
}
] WDYT? |
Ok, so we would implement the second case where the value is |
I don't think there is a difference in practical terms - looks as though Postgres just records each case differently in the system catalogs: Using this query to retrieve information about column defaults: SELECT
a.attname AS column_name,
pg_get_expr(ad.adbin, ad.adrelid) AS default_value
FROM
pg_catalog.pg_attrdef ad
JOIN pg_catalog.pg_attribute a ON ad.adnum = a.attnum
WHERE
a.attrelid = 'products'::regclass; a
whereas a dropped This is on Postgres 17; not sure if the behaviour is consistent between versions. It looks as though dropping a |
We no allow setting the value of `default` to `null` when altering a column. In practice this will cause us to drop the default. It is also possible to set `default` the *value* `NULL` which has a similar effect but is recorded slightly differently in the PG catalogue. (Details [here](#450 (comment))) Closes #450
The following operation is not supported natively by pgroll.
Current workaround is to use SQL the escape hatch.
The text was updated successfully, but these errors were encountered: