数据库操作小记

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))
相关推荐
mhkxbq15 小时前
济南H3C服务器升级方案怎么选?R4700G5等多型号来解答
运维·服务器
csdn2015_15 小时前
Set<String> 类型取第一条记录
开发语言·windows·python
csdn2015_15 小时前
List<String> 转换为Set<String>
windows·python·list
RisunJan15 小时前
Linux命令-mysqldump(MySQL数据库中备份工具)
linux·数据库·mysql
我是一颗小小的螺丝钉15 小时前
headscale安装与使用(linux)
linux·运维·服务器
Chen--Xing15 小时前
Python -- 正则表达式
python·正则表达式·数据分析·数据脱敏·2025年能源网络安全大赛
IMPYLH15 小时前
Linux 的 head 命令
linux·运维·服务器·bash
DolphinDB智臾科技15 小时前
直播回顾 | 物联网时序数据库如何驱动电力场景智能调度?
数据库·物联网·时序数据库
不愿透露姓名的大鹏15 小时前
Linux生产环境性能优化:内存优先策略,彻底规避Swap性能损耗
linux·运维·服务器·性能优化
郝学胜-神的一滴15 小时前
解锁CS数据存储的核心逻辑:从结构选择到表单设计的全解析
linux·服务器·数据库·c++·后端·oracle