数据库操作小记

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))
相关推荐
周末也要写八哥20 分钟前
数据库安装 | SQL Server2022安装教程及网盘下载地址
数据库
码农飞哥31 分钟前
我把RAG召回率从60%提到90%,就改了这两件事
python·知识库·向量检索·rag·效果提示
李燚32 分钟前
erlang_migrate 架构拆解:behaviour 驱动的多数据库迁移引擎
数据库·postgresql·架构·erlang·migrate·behaviour·erlang_migrate
宸津-代码粉碎机32 分钟前
Spring AI企业级实战|从RAG优化到Agent多工具调度
java·大数据·人工智能·后端·python·spring
yuhuofei202134 分钟前
【Python入门】Python中的字典dict
python
Jinkxs1 小时前
PostgreSQL - 全文检索的开启与基础使用
数据库·postgresql·全文检索
Jinkxs1 小时前
Python基础 - 文件的写入操作 write与writelines方法
android·服务器·python
情绪总是阴雨天~1 小时前
检索增强生成 (RAG) 四大检索策略详解
数据库·prompt·检索增强
初学Python的小明1 小时前
Python格式化输出、运算符、分支&循环
python
学Linux的语莫1 小时前
redis的数据类型和使用
数据库·redis·缓存