数据库操作小记

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))
相关推荐
AAA@峥3 分钟前
系统化学习 MySQL:数据类型、库表管理、增删改查全解析
数据库·学习·mysql
海阔天空任鸟飞~7 小时前
Linux 权限 777
linux·运维·服务器
流星白龙7 小时前
【Redis】2.Redis重大版本
数据库·redis·junit
流星白龙7 小时前
【Redis】7.Hash表
数据库·redis·哈希算法
love530love7 小时前
OpenClaw Windows Companion 桌面客户端 连接 LM Studio 完整配置指南
人工智能·windows·python·openclaw
流星白龙8 小时前
【Redis】4.基本全局命令
数据库·redis·缓存
王八八。9 小时前
Navicat 17破解版下载安装教程 附安装激活步骤(2026 最新版)
数据库·navicat
cui_ruicheng9 小时前
Python从入门到实战(十六):多进程编程
开发语言·python
Jelena1577958579210 小时前
电商运营分析数据比价接口实战:多平台价格监控与智能决策系统
java·大数据·数据库
Kina_C10 小时前
Linux iptables 防火墙原理与实操——从四表五链到 NAT 配置
linux·运维·服务器·iptables