数据库操作小记

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))
相关推荐
冬奇Lab3 小时前
每日一个开源项目(第134篇):Zvec - 阿里开源的嵌入式向量数据库,向量搜索界的 SQLite
数据库·人工智能·llm
hboot3 小时前
AI工程师第二课 - 数据处理
人工智能·python·数据分析
用户8356290780518 小时前
使用 Python 自动化 PowerPoint 形状布局与格式设置
后端·python
用户83562907805110 小时前
用 Python 自动化 PowerPoint 演讲者备注添加
后端·python
ClouGence14 小时前
Oracle CDC 架构优化:从主库直连到 DataGuard 备库同步
数据库·后端·oracle
黄忠15 小时前
01-系统架构设计-LangGraph状态机与多源异构RAG
python
zzzzzz31015 小时前
假如我是掘金管理员,我先给评论区装个'代码审查'系统
python·程序员·机器人
无响应de神16 小时前
三、用户与权限管理
数据库·mysql
砍材农夫16 小时前
python环境|conda安装和使用(2)
后端·python
程序员龙叔1 天前
编写高质量 Skill 系列 -- 如何设计需求分析与用例生成的 SKILL
自动化测试·软件测试·python·软件测试工程师·接口测试·性能测试·skill·ai测试