我想使用Alembic将数据库的列类型从字符串更改为整数.如果我使用纯SQL,它实现了目标:
alter table statistic_ticket alter column tags type bigint using tags::bigint;
Run Code Online (Sandbox Code Playgroud)
但是当我使用Alembic时:
import sqlalchemy as sa
def upgrade():
    op.alter_column('statistic_ticket', 'tags', nullable = True, existing_type=sa.String(length=255), type_=sa.Integer, existing_nullable=True)
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:
HINT: Please use USING clause for carrying out the conversion
Run Code Online (Sandbox Code Playgroud)
SQLAlchemy生成的SQL语句是:
ALTER TABLE statistic_ticket ALTER COLUMN tags TYPE INTEGER' {}
Run Code Online (Sandbox Code Playgroud)
有人可以告诉我怎么做alembic或SQLAlchemy中的SQL op.execute(SQL)吗?
我有一个输入文件test.txt as:host:dc2000 host:192.168.178.2
我希望通过以下方式获取这些机器的所有地址:
host:dc2000
host:192.168.178.2
Run Code Online (Sandbox Code Playgroud)
依此类推,我通过python获得命令输出:
grep "host:" /root/test.txt 
Run Code Online (Sandbox Code Playgroud)
但结果是空字符串.
我不知道我遇到了什么问题.你能建议我怎么解决?