数据库操作小记

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))
相关推荐
zmzmzmalo1 小时前
Linux ELF文件加载与内存管理揭秘
linux·网络·数据库
安_7 小时前
如何构建和使用向量索引?HNSW 和 IVF 有什么区别?
python·ai
三言老师7 小时前
K8s集群运行时自动化运维全覆盖落地实操(下)
linux·运维·服务器·网络
Super 含8 小时前
Android 启动优化(五):线程、GC 与 IO 为什么会拖慢启动?
java·服务器·数据库
counting money8 小时前
Java IO流详解:从InputStream到文件操作实战
java·开发语言·python
ltl9 小时前
向量检索引擎选型:决策树、RAG 回链与开放问题
数据库
坚持学习前端日记9 小时前
Python SQLAlchemy ORM 从0到1精通实战手册(基础到复杂高阶)
数据库·python·oracle
灯澜忆梦9 小时前
【MySQL17】进阶篇 | InnoDB引擎
数据库·mysql
北斗落凡尘9 小时前
LangGraph 入门实战(11)--输出模式
后端·python·langchain
anxiao_m9 小时前
2026制造业云桌面选型攻略,不同生产场景适配方案汇总
大数据·网络·数据库