数据库操作小记

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))
相关推荐
LaughingZhu1 小时前
Product Hunt 每日热榜 | 2026-02-14
数据库·人工智能·经验分享·神经网络·搜索引擎·chatgpt
geovindu1 小时前
python: Memento Pattern
开发语言·python·设计模式·备忘录模式
软件派2 小时前
近两年国外主流数据库深度解析:从技术特性到场景适配
数据库
寻星探路2 小时前
【JVM 终极通关指南】万字长文从底层到实战全维度深度拆解 Java 虚拟机
java·开发语言·jvm·人工智能·python·算法·ai
Elastic 中国社区官方博客2 小时前
DevRel 通讯 — 2026 年 2 月
大数据·数据库·人工智能·elasticsearch·搜索引擎·ai·jina
lbb 小魔仙2 小时前
【Java】Java 实战项目:手把手教你写一个电商订单系统
android·java·python
鸠摩智首席音效师2 小时前
如何在 Linux 中将文件复制到多个目录 ?
linux·运维·服务器
岱宗夫up2 小时前
FastAPI入门(上篇):快速构建高性能Python Web API
开发语言·前端·python·fastapi
Dxy12393102162 小时前
中文乱码恢复方案
开发语言·python
香蕉你个不拿拿^2 小时前
Linux进程地址空间解析
linux·运维·服务器