python - 使用 sqlalchemy 从 PostgreSQL 数据库中的列更新单个值
问题描述
我的 postgresql 数据库上有一个“批处理”表,我想更改“id”列中的单个值,将 70 替换为 15:
from sqlalchemy import create_engine
# Connection with DB
engine = create_engine('postgresql://xxx')
engine.connect()
# Update the value
...
解决方案
# Connection with DB
engine = create_engine('postgresql://xxx')
engine.connect()
# Update the value
sql = f"""
UPDATE batch
SET id=15
WHERE id=70
"""
with engine.begin() as conn: # TRANSACTION
conn.execute(sql)
推荐阅读
- php - 在 mysql 表中按日期 > 日期从分组表中选择
- javascript - Internet Explorer CSS 或 JS 问题导致预加载器保持正常运行并且猫头鹰轮播无法正常工作
- android - 从片段中获取输入
- python - 计算数据集的平均值,混合文本
- c# - C# Aforge 库和保存位图分辨率?
- angular - Angular 5 - 将带有 HTML 内容的 POST 请求发送到 OneNote API
- c++ - C++ 将 int 转换为 wchar_t*
- angular - 用于在角度 2、4 中构建树状结构的节点模块
- javascript - 如何在特定区域填充颜色?
- jquery - 将 base64 编码的 src 设置为插件 jquery