数据库操作小记

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))
相关推荐
渣渣盟2 小时前
2000万QPS背后的存储引擎博弈:InnoDB、MyRocks、WiredTiger到底谁更强?
数据库·mysql
硅基手札2 小时前
【Linux 内核专栏 17】进程间通信 IPC(上)— 管道·信号·System V IPC·mmap·文件锁
linux·运维·服务器·stm32·单片机·mcu
小能喵2 小时前
kismet -h 帮助信息 中文版
linux·服务器·网络
seuzhouchenglong2 小时前
服务器通过本地电脑连接本地开发板
运维·服务器
ss2732 小时前
AI时代首先数据库-PostgreSQL实战笔记 | 11 PostgreSQL安装部署常见问题排查与解决
数据库·笔记·postgresql
ydjs678899-bot2 小时前
如何在Java中打印pdf静默打印和打印对话框选择
java·python·pdf
张张123y2 小时前
# 后端第八课:数据库入门(给 FastAPI 接口加上“记忆“,存下问答历史)
数据库·sql·mysql·oracle·fastapi·sqllite
臻选云栗子2 小时前
PCDN晚高峰掉量原因分析及优化建议
服务器·网络·安全·网络安全·阿里云·云计算·信息与通信
YumiProxy2 小时前
流媒体区域内容访问:代理IP的技术原理、检测机制与稳定性优化
服务器·网络·网络协议·tcp/ip·ip
cspttty2 小时前
2027秋招市场调研岗:统计学专业如何补齐业务、SQL与研究交付能力
大数据·数据库