数据库操作小记

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))
相关推荐
赟爸几秒前
直播切片素材杂乱不好复用,易元AI要怎么处理
大数据·人工智能·python
yunlaodacom7 分钟前
阿里云国际站注册:性能损耗 < 1%!基于 eBPF 的服务器异常预测实战与调优指南
大数据·服务器·阿里云
好评12426 分钟前
【Linux】进程信号
linux·运维·服务器
怪奇云呼军39 分钟前
从声音特征到 CRM 回流:闪电智能 Voice Agent 沟通策略自适应系统 v1 实战
android·人工智能·python·音视频·语音识别
jufeng13071 小时前
【系列:手搓自主 AI Agent:Hermes 架构原理剖析 · 第 6 篇】
python·ai agent·记忆系统
kevinnett1 小时前
别再把模型地址写死了:用 Python 设计一个可切换的 LLM 调用层
python
曹牧2 小时前
C#:问号
前端·数据库·c#
奇树谦2 小时前
《现代 Key-Value 数据库原理:从 B+Tree 到 LSM Tree》-第五篇:现代数据库横向对比
数据库·lsm-tree
李白客2 小时前
分布式集群与数据库产业:从单机到集群的架构跃迁与市场重构
数据库·分布式·架构
天天进步20152 小时前
Python全栈项目--协同办公平台
开发语言·python