数据库操作小记

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))
相关推荐
应用市场1 小时前
构建自定义命令行工具 - 打造专属指令体
开发语言·windows·python
东方佑1 小时前
从字符串中提取重复子串的Python算法解析
windows·python·算法
言德斐1 小时前
SQL性能优化的思路及策略
数据库·sql·性能优化
Dfreedom.2 小时前
一文掌握Python四大核心数据结构:变量、结构体、类与枚举
开发语言·数据结构·python·变量·数据类型
一半烟火以谋生2 小时前
Python + Pytest + Allure 自动化测试报告教程
开发语言·python·pytest
码界奇点2 小时前
Django视图从基础到高级的全面解析
数据库·django·sqlite·web·python3.11
Allan_20252 小时前
数据库学习
数据库·学习
fen_fen2 小时前
人大金仓数据库kingbase8创建表示例
数据库·oracle
一勺菠萝丶2 小时前
「您的连接不是私密连接」详解:为什么 HTTPS 证书会报错,以及如何正确配置子域名证书
数据库·网络协议·https
ximy13352 小时前
AI服务器工作之线材的接口介绍
运维·服务器