数据库操作小记

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))
相关推荐
金銀銅鐵10 小时前
[Python] 扩展欧几里得算法
python·数学·算法
Duckdblab10 小时前
DuckDB 性能调优终极指南:打造闪电般的分析体验
python
带派擂总11 小时前
Python全栈开发精华版最全合集(包含各种面试题) Day24_异常和错误
python
笃行35013 小时前
金仓数据库数据安全双防线:静态存储加密与传输加密实战
数据库
笃行35013 小时前
金仓数据库物理备份实战:sys_rman 全流程演练与误覆盖抢救
数据库
笃行35013 小时前
金仓数据库逻辑备份实战:从全库导出到 Schema 替换的完整闭环
数据库
金銀銅鐵14 小时前
n^5 和 n 的个位数是否总相等?
python·数学
aqi0017 小时前
15天学会AI应用开发(九)利用Chroma持久化向量数据
人工智能·python·大模型·ai编程·ai应用