数据库操作小记

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))
相关推荐
童话的守望者13 小时前
matrix-breakout-2-morpheus靶机通关
linux·运维·服务器
卢傢蕊13 小时前
PostgreSQL 初体验
数据库·postgresql
Frank_refuel13 小时前
Linux操作系统 -> 进程信号(上)
linux·运维·服务器
softshow102613 小时前
PostgreSQL 12 完整部署+迁移+数据恢复
数据库·postgresql
港股研究社13 小时前
广汽年报里的隐线:组织改革、生态协同与修复起点
python
Sirius.z13 小时前
第T11周:优化器对比实验
python
loriloy13 小时前
Python 环境管理工具 pyenv-win (windows版本)
windows·python·pyenv-win
bearpping13 小时前
关于Mysql 中 Row size too large (> 8126) 错误的解决和理解
数据库·mysql
zhuiyisuifeng13 小时前
PostgreSQL_安装部署
数据库·postgresql
watersink13 小时前
第15章 数据库系统
数据库