在sqlalchemy中使用DATEADD

编程入门 行业动态 更新时间:2024-10-25 00:23:48
本文介绍了在sqlalchemy中使用DATEADD的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我怎样才能用python中的sqlalchemy重写下面的sql语句。我一直在寻找30分钟,但仍然找不到任何解决方案。

DATEADD(NOW(),INTERVAL 1 DAY)

INSERT INTO日期(过期) VALUES(DATEADD(NOW(),INTERVAL 1 DAY))

提前致谢解决方案SQLAlchemy的日期自动映射到Python日期时间对象,所以您应该能够 pre $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ 元数据元数据()示例=表('users',元数据,列('expire',DateTime)) 明天= datetime.now()+ timedelta(days = 1) ins = example.insert()。values(expire = tomorrow)

How can I rewrite the following sql statement with sqlalchemy in python. I have been searching for 30 mins but still couldn't find any solutions.

DATEADD(NOW(), INTERVAL 1 DAY)

or

INSERT INTO dates (expire) VALUES(DATEADD(NOW(), INTERVAL 1 DAY))

Thanks in advance

解决方案

SQLAlchemy dates automagically map to Python datetime objects, so you should just be able to do:

from sqlalchemy import Table, Column, MetaData, DateTime from datetime import datetime, timedelta metadata = MetaData() example = Table('users', metadata, Column('expire', DateTime) ) tomorrow = datetime.now() + timedelta(days=1) ins = example.insert().values(expire=tomorrow)

更多推荐

在sqlalchemy中使用DATEADD

本文发布于:2023-10-13 10:31:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1487708.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:sqlalchemy   DATEADD

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!