数据库操作小记

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 分钟前
数据库管理-第376期 Oracle AI DB 23.26新特性一览(20251016)
数据库·人工智能·oracle
麦聪聊数据15 分钟前
浅谈SQL审核(一):SQL审核实现方式与常见工具的选择
数据库·sql
楠木s15 分钟前
ctfshow pwn44
linux·服务器·网络·安全·网络攻击模型·二进制
ajassi200022 分钟前
开源 Linux 服务器与中间件(七)数据库--MySQL
linux·服务器·数据库·ubuntu·开源
韩立学长38 分钟前
【开题答辩实录分享】以《自然灾害隐患点管理信息系统》为例进行答辩实录分享
数据库·spring boot
迎風吹頭髮1 小时前
Linux服务器编程实践58-getnameinfo函数:通过socket地址获取主机名与服务名
开发语言·数据库·php
一吃就胖的1 小时前
【给服务器安装服务器安装nacos】
java·运维·服务器
小云数据库服务专线1 小时前
GaussDB 应用侧报no pg_hba.conf entry for host处理方法
服务器·网络·gaussdb
christine-rr1 小时前
linux常用命令——其他
linux·服务器·网络·数据库·redis·ubuntu
zhaotiannuo_19981 小时前
虚拟机安装ikuai系统相关配置
运维·服务器·性能优化