snowflake-sqlalchemy
snowflake-sqlalchemy copied to clipboard
SNOW-159471 Alembic op.alter_column generates invalid SQL for rename
Please answer these questions before submitting your issue. Thanks!
- What version of Python are you using (
python --version)?
3.7
-
What operating system and processor architecture are you using (
python -c 'import platform; print(platform.platform())')? -
What are the component versions in the environment (
pip list)?
Package Version
-------------------------- ---------
alembic 1.3.2
snowflake-connector-python 2.1.2
snowflake-sqlalchemy 1.1.17
sqlacodegen 2.1.0
SQLAlchemy 1.3.12
- What did you do? alembic migration with the following spec
op.alter_column(
"t",
"c1",
new_column_name="c2",
schema="s",
)
- What did you expect to see?
Correctly changed table name
- What did you see instead?
Invalid SQL: RENAME instead of RENAME COLUMN
- Can you set logging to DEBUG and collect the logs?
sqlalchemy.exc.ProgrammingError: (snowflake.connector.errors.ProgrammingError) 001003 (42000): SQL compilation error:
syntax error line 1 at position 34 unexpected 'c1'.
[SQL: ALTER TABLE s.t RENAME c1 TO c2]
BTW, yes I know this can be worked around with op.execute
We are seeing this issue, too. Any updates?
Hey people, I triaged the issue and I'm sad to say that I can't fix this for you as we don't have a snowflake-alembic package.
However, I can tell you how to fix the behaviour yourself.
Just add the following code to the class we tell you to create here: https://github.com/snowflakedb/snowflake-sqlalchemy#alembic-support
@compiles(ColumnName)
def visit_column_name(element, compiler, **kw):
return "%s RENAME COLUMN %s TO %s" % (
alter_table(compiler, element.table_name, element.schema),
format_column_name(compiler, element.column_name),
format_column_name(compiler, element.newname),
)
and don't forget to:
from alembic.ddl.base import alter_table, format_column_name, ColumnName
from sqlalchemy.ext.compiler import compiles
To clean up and re-prioritize bugs and feature requests we are closing all issues older than 6 months as of Apr 1, 2023. If there are any issues or feature requests that you would like us to address, please re-create them. For urgent issues, opening a support case with this link Snowflake Community is the fastest way to get a response