数据库操作小记

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))
相关推荐
大房身镇、王师傅4 分钟前
【VirtualBox】VirtualBox 7.1.6 RockyLinux10 配置增强功能 设置共享目录
运维·服务器·virtualbox·rockylinux10
_F_y11 分钟前
MySQL表的操作
android·数据库·mysql
betazhou13 分钟前
rsync使用案例分析
linux·运维·服务器·rsync·同步数据
SmartBrain30 分钟前
Agent 知识总结
服务器·数据库·笔记
白云千载尽30 分钟前
LQR与MPC.入门知识与实验
python·控制·mpc·lqr
weixin_4331793332 分钟前
Hangman 猜字游戏使用列表List实现
开发语言·python
QQ__176461982444 分钟前
为Windows系统安装Codex(保姆级教程)
服务器·大模型·codex
fenglllle1 小时前
MySQL explain format的差异
数据库·mysql
52Hz1181 小时前
二叉树理论、力扣94.二叉树的中序遍历、104.二叉树的最大深度、226.反转二叉树、101.对称二叉树
python·算法·leetcode
卖个几把萌1 小时前
解决 Python 项目依赖冲突:使用 pip-tools 一键生成现代化的 requirements.txt
开发语言·python·pip