数据库操作小记

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))
相关推荐
本地化文档3 分钟前
psycopg3-docs-l10n
数据库·python·postgresql·github·gitcode·sphinx
Safeploy安策数据3 分钟前
从算法到架构:构建企业级数据库加密与密钥防护体系的实战手册
数据库·安全·架构
呉師傅5 分钟前
EPSON爱普生 L3118打印头【喷头】清洗方法
运维·服务器·网络·学习·电脑
JeJe同学14 分钟前
LabelImg 标签字体大小修改教程
linux·人工智能·python
小鸡毛程序员17 分钟前
从零搭建 Linux 开发服务器:VMware NAT 静态网络 + Docker + MySQL + Redis + 云服务器迁移
linux·服务器·网络
Irissgwe22 分钟前
【无标题】
python·langchain·ai编程·langgraph
Litluecat24 分钟前
信创改造,Oracle切海量数据库,语法与类型坑
数据库·sql·oracle·信创·字段类型·海量
星越华夏36 分钟前
MongoDB安装实战指南
数据库·mongodb
RSTJ_162536 分钟前
PYTHON+AI LLM DAY SIXTY-SIX
服务器·开发语言·python
川石课堂软件测试36 分钟前
性能测试|JMeter常用线程组设置策略
大数据·数据库·功能测试·测试工具·jmeter·mysql·单元测试