数据库操作小记

PG之最近的年月日小时查询

sql 复制代码
SELECT * from pool where published_at >= CURRENT_DATE - INTERVAL '6 months' order by published_at desc 
#years、months、days、hours、minutes

ORM and、or、以及其他查询的嵌套

python3 复制代码
or_clause = []
for p in content:
    and_clause = [P.chain == p["chain"]]
    if p.get("min") and p.get("max"):
        and_clause.append(P.liquidity.between(p["min"], p["max"]))
    elif p.get("min"):
        and_clause.append(P.liquidity >= p["min"])
    elif p.get("max"):
        and_clause.append(P.liquidity <= p["max"])

    or_clause.append(and_(*and_clause))
pool_info = pool_info.filter(or_(*or_clause))
相关推荐
倔强的石头_3 分钟前
MySQL 兼容性深度解析:从内核级优化到“零修改”迁移工程实践
前端·数据库
小小小米粒3 分钟前
k8s流程创建清单
服务器·前端·etcd
水杉i10 分钟前
Redis 使用笔记
数据库·redis·笔记
学不完的10 分钟前
redis
数据库·redis·缓存·运维开发
无效的名字13 分钟前
最快速在服务器上搭建代理
运维·服务器
木与长清15 分钟前
人鼠同源基因离线转换
数据库·矩阵·数据分析·r语言
wanhengidc19 分钟前
服务器 数据安全稳定
运维·服务器·数据库·游戏·智能手机
tingting011919 分钟前
linux系统-统计连接数-钉钉告警
linux·数据库·钉钉
山峰哥20 分钟前
数据库工程中的SQL调优策略与实践:从索引优化到执行计划分析
数据库·sql·性能优化
0wioiw021 分钟前
Google-Oauth
python