小编Sie*_*ruc的帖子

如何在Alembic/SQLAchemy中使用USING子句?

我想使用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)吗?

python postgresql sqlalchemy alembic

12
推荐指数
1
解决办法
1152
查看次数

如何获取grep命令的输出(Python)

我有一个输入文件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)

但结果是空字符串.

我不知道我遇到了什么问题.你能建议我怎么解决?

python grep subprocess

4
推荐指数
2
解决办法
2万
查看次数

标签 统计

python ×2

alembic ×1

grep ×1

postgresql ×1

sqlalchemy ×1

subprocess ×1