数据库操作小记

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))
相关推荐
程序员小崔日记4 小时前
20块钱注册一年 .COM 域名!Spaceship 最新优惠教程,支付宝即可付款(附优惠码)
服务器·腾讯云·域名
ShiXZ2134 小时前
Redis 常用指令全集:redis-cli 实战速查手册
数据库·redis·缓存
RSABLOCKCHAIN5 小时前
AI Agents in LangGraph-2
人工智能·python
晓子文集5 小时前
Tushare接口文档:期货日线行情(fut_daily)
大数据·数据库·金融数据·量化投资·tushare
实心儿儿5 小时前
Linux —— 进程间关系和守护进程
linux·运维·服务器
WA内核拾荒者5 小时前
WhatsApp 账号异常检测的自动化告警系统设计
数据库·python·自动化
林浅不想努力5 小时前
LVS知识点总结
服务器·云原生·lvs
码流怪侠6 小时前
【GitHub】Bend:让 GPU 并行编程像写 Python 一样简单
python·github
Dawn-bit6 小时前
Linux磁盘管理详解
linux·运维·服务器·计算机网络·云计算