数据库操作小记

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))
相关推荐
写代码的强哥12 小时前
TiDB 和 OceanBase 对比:架构师视角下的企业选型实战指南
数据库·云原生·架构
Dear~yxy13 小时前
LVS企业级实战
linux·服务器·lvs
min(a,b)13 小时前
学习第 6 天:类型注解、装饰器与高级特性
python·学习
兮动人13 小时前
Python字符串类型
开发语言·python·python字符串类型
码云骑士13 小时前
80-指令微调Instruction-Tuning-指令数据构造-多任务训练-过拟合检测
python
Sirius Wu14 小时前
OpenClaw Model Provider(模型提供商)完整详解
服务器·网络·人工智能·安全·aigc
金融小白数据分析之路14 小时前
绍兴市镇街echarts 制作
前端·数据库·echarts
桐薇全肯定14 小时前
MySQL学生成绩管理系统实战操作
java·数据库·sql
爱昏羔14 小时前
上篇:从PDF到向量库 — 物流行业RAG系统的知识库构建全解析
python·langchain·pdf·agent·rag
Sagittarius_A*14 小时前
[LitCTF2026] lit_xor_two_story
python·算法·密码学