数据库操作小记

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 小时前
多因子智能推演:油价回落6%与黄金震荡上行的关联解析——AI预测框架
大数据·python·深度学习
BUG研究员_5 小时前
Runnable与LCEL
开发语言·人工智能·python
老马聊技术5 小时前
Pytorch深度学习环境配置与测试
人工智能·pytorch·python
范什么特西5 小时前
回答知识总结04(redis)
数据库·redis·缓存
码农颜5 小时前
5.4.1 锁分类
java·数据库·mysql
Python私教6 小时前
AI Agent 上生产要不要开写权限?我把执行链拆成 4 道闸门
人工智能·后端·python
天才测试猿6 小时前
软件测试知识总结(基础篇)
自动化测试·软件测试·python·功能测试·测试工具·职场和发展·测试用例
云深处@6 小时前
【数据库】MySQL 入门
数据库·学习·mysql
梦远星帆6 小时前
SQLyog社区版下载
数据库·mysql·sqlyog