数据库操作小记

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))
相关推荐
AC赳赳老秦14 分钟前
政企内网落地:OpenClaw 离线环境深度适配方案,无外网场景下本地化模型对接与全功能使用
java·大数据·运维·python·自动化·deepseek·openclaw
星越华夏28 分钟前
python 将相对路径变成绝对路径
python
念何架构之路30 分钟前
MySql常见ORM
数据库·mysql
l1t31 分钟前
mingw和Linux中的gcc和llvm编译器编译的pocketpy执行同一个python脚本的不同效果
linux·运维·python
砚底藏山河42 分钟前
股票数据API接口:如何获取股票历历史分时KDJ数据
java·python·maven
web3.08889991 小时前
天猫API接口详解:商品详情与关键词搜索商品指南及代码示例
python·json
Csvn1 小时前
Python 性能优化与 Profiling 工具
后端·python
xcLeigh1 小时前
KES数据库安全、权限、审计实战
数据库·安全·备份·权限·审计·ssl加密·密码策略
白緢1 小时前
一、Linux 基础入门
linux·运维·服务器
zjy277771 小时前
c++如何实现日志文件的异步落盘功能_基于无锁队列方案【附代码】
jvm·数据库·python