-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
sql: move alter column type general support out of experimental #49329
Comments
Hi @RichardJCai, I've guessed the C-ategory of your issue and suitably labeled it. Please re-label if inaccurate. While you're here, please consider adding an A- label to help keep our repository tidy. 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan. |
When running Django's test suite, I'm seeing FeatureNotSupported errors pointing to this issue that weren't present before 20.2 alpha 2.
Is this a regression? I'll provide the exact SQL statements if needed. |
Yeah this is a regression, while adding experimental support for other cases of alter column type, I wrapped all uses of alter column type with the error, will fix this soon. |
Actually can you provide the statements please? Curious if you're providing an expression to alter the column type or not. |
ALTER TABLE "schema_author" ALTER COLUMN "name" TYPE text USING "name"::text;
ALTER TABLE "schema_uniquetest" ALTER COLUMN "year" TYPE bigint USING "year"::bigint;
ALTER TABLE "schema_smallintegerpk" ALTER COLUMN "i" TYPE smallint USING "i"::smallint; |
@timgraham actually this isn't necessarily a regression - previously the logic did not take into account the USING expression at all. Now if any expression is provided, we force a change to happen. The examples you gave, the expression is ignored and the ALTER TABLE is a no-op. How important is this? |
Maybe Django doesn't need to add a USING clause (that code was copied from the PostgreSQL backend). Removing that resolves the crashes. diff --git a/django_cockroachdb/schema.py b/django_cockroachdb/schema.py
index 11d90dc..ca2a9da 100644
--- a/django_cockroachdb/schema.py
+++ b/django_cockroachdb/schema.py
@@ -44,9 +44,6 @@ class DatabaseSchemaEditor(PostgresDatabaseSchemaEditor):
def _alter_column_type_sql(self, model, old_field, new_field, new_type):
self.sql_alter_column_type = 'ALTER COLUMN %(column)s TYPE %(type)s'
- # Cast when data type changed.
- if self._field_data_type(old_field) != self._field_data_type(new_field):
- self.sql_alter_column_type += ' USING %(column)s::%(type)s'
# Make ALTER TYPE with SERIAL make sense.
# table = strip_quotes(model._meta.db_table)
serial_fields_map = {'bigserial': 'bigint', 'serial': 'integer', 'smallserial': 'smallint'} Incidentally, I added "SET enable_experimental_alter_column_type_general = true" and enabled some type change tests without issue. The remaining type conversion test failures are covered by #47636. |
For what it's worth, here are the failures on PostgreSQL when I remove the USING clause. I guess CockroachDB does these casts implicitly.
|
Text mismatch in primary key error with pg dialect, in crdb: alter table "t1" alter column "id" drop not null - column "id" is in a primary index in pg: alter table "t1" alter column "id" drop not null - column "id" is in a primary key Check on CockroachDB CCL v21.2.4 (x86_64-unknown-linux-gnu, built 2022/01/10 18:50:15, go1.16.6) CREATE TABLE public.t1 (
id INT8 NOT NULL,
rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(),
CONSTRAINT t1_pkey PRIMARY KEY (id ASC),
FAMILY "primary" (id, rowid)
) In query: SET enable_experimental_alter_column_type_general = true;
alter table "t1" alter column "id" type integer using ("id"::integer); |
Added the following two items to the bullet list at top, as per request from @dbist 👍
|
Any hope? |
Currently ALTER COLUMN TYPE for non-trivial casts is only supported experimentally.
Things to do:
Enhancements:
sql_safe_updates
is false.Bugs:
Jira issue: CRDB-4238
Epic CRDB-25314
The text was updated successfully, but these errors were encountered: