数据库操作小记

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))
相关推荐
夏语灬16 分钟前
cryptography:Python 密码学标准库的终极选择
开发语言·python·密码学
源图客26 分钟前
Minio配置HTTPS服务
服务器·网络协议·https
修炼室31 分钟前
外网环境原生直连校内服务器:基于内网穿透 + SSH 密钥认证的完整实践指南
服务器·ssh·php
我不介意孤独1 小时前
04-记忆系统为什么向量数据库不够用
数据库·人工智能·资源隔离·agent infra
CTA终结者1 小时前
期货开仓前保证金够吗:get_account 可用与占用字段对照
python·区块链
开源量化GO1 小时前
夜盘白盘衔接几分钟误下单:天勤交易时段与行情过滤
python·区块链
Titan20241 小时前
Linux动静态库
linux·服务器·c++
AOwhisky1 小时前
MySQL 学习笔记(第六期):MySQL 备份与恢复
运维·数据库·笔记·学习·mysql·云计算
辣椒思密达1 小时前
Python公开数据采集实战:如何解决请求高频拦截与Session会话中断问题
开发语言·python
qq21084629532 小时前
【数据库】TDengine 清理旧数据
数据库·oracle·tdengine