数据库操作小记

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))
相关推荐
AI街潜水的八角1 小时前
Python电脑屏幕&摄像头录制软件(提供源代码)
开发语言·python
hadage2331 小时前
--- git 的一些使用 ---
开发语言·git·python
LSL666_3 小时前
1 概述及简单登录(不涉及数据库)
数据库·servlet
qq_479875436 小时前
X-Macros(1)
linux·服务器·windows
q***06476 小时前
MySQL的UPDATE(更新数据)详解
数据库·mysql
8***B6 小时前
MySQL性能
数据库·mysql
q***72196 小时前
oracle使用PLSQL导出表数据
数据库·oracle
数据库生产实战6 小时前
Oracle DG备库日志切换解析,Private strand flush not complete如何理解?(基础知识)
数据库·oracle
百***75747 小时前
从 SQL 语句到数据库操作
数据库·sql·oracle