如何?CURRENT_TIMESTAMP时区'UTC'

Jon*_*sco 20 python sqlalchemy

我如何修改我的电话

sqlalchemy.func.current_timestamp()
Run Code Online (Sandbox Code Playgroud)

带来的东西

CURRENT_TIMESTAMP AT TIME ZONE 'UTC'
Run Code Online (Sandbox Code Playgroud)

Aud*_*kas 35

快速解决方法是执行以下操作:

func.current_timestamp().op('AT TIME ZONE')('UTC')
Run Code Online (Sandbox Code Playgroud)

更合适的方法是使用编译器扩展并定义自定义编译CURRENT_TIMESTAMP.实际上,它的文档中已经有一个例子,它使用了不同的方法(TIMEZONE函数).因为你只需要这个用于Postgres(我假设您之前在SA邮件列表中的电子邮件中使用的是Postgres),这里是另一个(更好的)快速修复:

func.timezone('UTC', func.current_timestamp())
Run Code Online (Sandbox Code Playgroud)

  • 如果在`Column`定义中的`server_default`中使用该函数,那么这些都不起作用; 在这种情况下,引用示例中的方法(现在[here](http://docs.sqlalchemy.org/en/latest/core/compiler.html#utc-timestamp-function))确实有效. (2认同)