数据库操作小记

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))
相关推荐
小蒜学长1 分钟前
python餐厅点餐系统(代码+数据库+LW)
数据库·spring boot·后端·python
山土成旧客1 分钟前
【Python学习打卡-Day34】GPU为何“变慢”?从性能悖论到`__call__`的魔力
开发语言·python·学习
额呃呃3 分钟前
poll的细节分析
服务器
岳麓丹枫0014 分钟前
PostgreSQL 中 create database 中的注意事项
数据库·postgresql
水龙吟啸5 分钟前
项目设计与开发:智慧校园食堂系统
python·机器学习·前端框架·c#·团队开发·visual studio·数据库系统
梦想画家5 分钟前
告别关键词!PostgreSQL+pgvector 玩转语义和图像检索
数据库·postgresql
极客小云9 分钟前
【IEEE Transactions系列期刊全览:计算机领域核心期刊深度解析】
android·论文阅读·python
Hi梅19 分钟前
批量处理框架 (Batch Processing Framework)
java·服务器·batch
じ☆冷颜〃19 分钟前
基于多数据结构融合的密码学性能增强框架
数据结构·经验分享·笔记·python·密码学
无所事事的海绵宝宝23 分钟前
python基础
开发语言·python