数据库操作小记

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))
相关推荐
FreakStudio21 小时前
做了个Claude Code CLI 电子宠物:程序员的实体监工代码搭子
python·单片机·嵌入式·面向对象·并行计算·电子diy·电子计算机
柴米油盐那点事儿21 小时前
python+mysql+bootstrap条件搜索分页
python·mysql·flask·bootstrap
AC赳赳老秦21 小时前
OpenClaw二次开发实战:编写专属办公自动化技能,适配个性化需求
linux·javascript·人工智能·python·django·测试用例·openclaw
l1t1 天前
DeepSeek总结的PostgreSQL 19查询提示功能
数据库·postgresql
Ulyanov1 天前
《PySide6 GUI开发指南:QML核心与实践》 第二篇:QML语法精要——构建声明式UI的基础
java·开发语言·javascript·python·ui·gui·雷达电子对抗系统仿真
刀法如飞1 天前
一款Python语言Django框架DDD脚手架,助你快速搭建项目
python·ddd·脚手架
刀法如飞1 天前
一款Python语言Django框架DDD脚手架,适合中大型项目
后端·python·领域驱动设计
chenxu98b1 天前
MySQL如何执行.sql 文件:详细教学指南
数据库·mysql
MediaTea1 天前
Scikit-learn:数据集
人工智能·python·机器学习·scikit-learn
刘晨鑫11 天前
MongoDB数据库应用
数据库·mongodb