数据库操作小记

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))
相关推荐
ClouGence1 小时前
SQL Server CDC 能放到 Always On 备库读吗?一文讲透原理与实践
数据库·sql server
你好潘先生3 小时前
别再记命令了,用 yeero do 说句人话就能跑脚本,而且不烧 token
服务器·python·命令行
Agent_大师3 小时前
WebSocket 行情重连成功,K线缺口不会自动消失
python
荣码3 小时前
LLM结构化输出:让AI返回JSON而不是废话,我踩了4个坑
java·python
copyer_xyf3 小时前
FastAPI 如何连接 MySQL
后端·python
apocelipes16 小时前
常用编程语言和库的正则表达式性能对比
c语言·c++·python·性能优化·golang·开发工具和环境
先吃饱再说18 小时前
存储的进化:从 MySQL 到浏览器缓存,数据到底住在哪?
数据库
用户83562907805118 小时前
使用 Python 在 PDF 中创建与管理书签
后端·python
Nturmoils18 小时前
字段太多看不全,ksql 的展开模式和输出控制怎么用
数据库·后端
Databend21 小时前
Agent 轨迹分析与归因的数据工程实践
大数据·数据库·agent