在 postgres 中,您可以按会话或全局设置时间戳的默认格式吗? [英] in postgres, can you set the default formatting for a timestamp, by session or globally?

查看:8
本文介绍了在 postgres 中,您可以按会话或全局设置时间戳的默认格式吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Postgres 中,是否可以更改时间戳的默认格式掩码?

In Postgres, is it possible to change the default format mask for a timestamp?

现在回来了

2012-01-03 20:27:53.611489

我想像这样解决:

2012-01-03 20:27

我知道我可以使用 to_char() as 对单个列执行此操作,或者由接收应用程序使用 substr() 进行剥离,但最初格式正确将节省大量工作并减少大量错误.

I know I can do this on individual columns with to_char() as or stripped down with a substr() by the receiving app, but having it formatted correctly initially would save a lot of work and reduce a lot of errors.

推荐答案

在 postgres 中,您可以更改日期时间的默认格式掩码 - 使用 set datestyle 选项;可以在 这里找到可用的选项(参见 8.5.2.日期/时间输出).

In postgres, you can change the default format mask for datetimes - using the set datestyle option; the available options can be found here (see 8.5.2. Date/Time Output).

很遗憾,所有可用选项都包括秒数 - 因此您需要在查询或应用程序代码(如果适用)中重新格式化它们.

Unfortunately, all the available options include the number of seconds - you will therefore need to reformat them either in the query or the application code (if applicable).

这篇关于在 postgres 中,您可以按会话或全局设置时间戳的默认格式吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆