数据库操作小记

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))
相关推荐
小小小花儿19 分钟前
SSH密钥配置(免密连接远程服务器)
服务器·ssh
dishugj24 分钟前
iSCSI + Multipath + ASM:Oracle RAC 共享存储技术链详解
数据库·oracle
yoothey1 小时前
MySQL事务机制解析 - 面试高分知识点
数据库·mysql·面试
深圳恒讯1 小时前
越南服务器BGP多线和单线有什么区别?
运维·服务器
JOJO数据科学1 小时前
JupyterLab Electron 鸿蒙 PC 适配全记录:从 Python 原生崩溃到 node-static 本地工作台
python·electron·harmonyos
xufengzhu1 小时前
第三方 Python 库 redis-py + hiredis 的使用
开发语言·redis·python
Lkstar1 小时前
万字长文Query改写与多路召回实战|从HyDE到RRF融合,召回率提升22%的完整方案
数据库·人工智能·llm
IT新视界2 小时前
星环科技ArgoDB:基于一体化架构构建数据全生命周期安全底座
数据库·科技·安全·架构
峥无2 小时前
MySQL DML 操作(CRUD)总结
数据库·mysql
llxxyy卢2 小时前
polar夏季赛部分题目
开发语言·python