数据库操作小记

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))
相关推荐
RSTJ_162515 小时前
PYTHON+AI LLM DAY ONE HUNDRED AND TWENTY-NINE
人工智能·python
夏天测15 小时前
Python 网络编程从 TCP 三次握手到 Socket 搭建极简 AI 推理服务端(零基础可跑通完整代码)
python·socket·网络通信·tcp 网络编程·零基础网络编程
深念Y16 小时前
ZTE_UZ901_NVRAM经验总结
linux·服务器·网络·嵌入式硬件·嵌入式·随身wifi
Vec‑Jie16 小时前
MerchantOps-KBQA 实践(十四):本地运行、性能限制与可验证的交付边界
人工智能·后端·python·flask
05664616 小时前
RAG 向量检索:从“查字“到“查意“
数据库·人工智能·学习·oracle
bug嘛我经常写16 小时前
dbf文件UTF-8转GBK编码,以及两编码文件互转
数据库·python
知行合一。。。16 小时前
LangGraph--03--本地服务与 Studio 调试
数据库
胡耀超16 小时前
AI出事后,怎么查?——读《AI Forensics》
人工智能·python·数字取证·ai取证·
梦想三三16 小时前
Python从零实现AI Agent电商客服(Qwen/Ollama+SQLite源码解析)
人工智能·python·sqlite