简体   繁体   English

如何在PostgreSQL中更改日期样式

[英]How to change datestyle in PostgreSQL

I know this has been asked many times but no matter what I try in PostgreSQL 9.4, the datestyle will revert to ISO,MDY within a minute or so. 我知道这个问题已经问过很多遍了,但是无论我在PostgreSQL 9.4中尝试什么,datestyle都会在一分钟左右的时间内恢复为ISO,MDY。 I require the date format: 我需要日期格式:

SET datestyle to SQL,DMY;
Show datesyle;

Eg dd/mm/yyyy ... - After entering this, the 'show' command displays SQL,DMY 例如dd / mm / yyyy ...-输入后,“ show”命令显示SQL,DMY

SELECT NOW();

Displays the current date in correct format 以正确的格式显示当前日期

Each time I apply this setting and look at my date column it still turns my input into yyyy-mm-dd. 每次我应用此设置并查看日期列时,它仍然会将我的输入变为yyyy-mm-dd。 Then shortly after if i run: 然后不久,如果我运行:

Show datestyle;

It's back to ISO,MDY. 回到ISO,MDY。

I have applied the datestyles in three other ways: 我以其他三种方式应用了日期样式:

ALTER DATABASE "database" SET datestyle TO SQL,DMY;

ALTER USER "User" SET datestyle to SQL,DMY;
  • postgresql.config - Changed the datestyle variable and restarted the server postgresql.config-更改了datestyle变量并重新启动了服务器

I have spent hours looking up advice and tried editing LC_TIME and the results are the same. 我花了几个小时来查找建议,并尝试编辑LC_TIME,结果是相同的。

I suspect the answer is here: http://www.postgresql.org/docs/current/static/sql-set.html 我怀疑答案在这里: http : //www.postgresql.org/docs/current/static/sql-set.html

To quote " SET only affects the value used by the current session. " 引用“ SET仅会影响当前会话使用的值。

But I'm wondering why you are trying to force a default date style. 但是我想知道为什么您要强制使用默认的日期样式。 Just use YYYY-MM-DD in all your interactions. 只需在所有互动中使用YYYY-MM-DD。 It's the ISO standard! 这是ISO标准! When the value is supplied externally, convert it with to_date() and to output format it with to_char() . 当值由外部提供时,将其转换为to_date()并使用to_char()输出格式。

What worked for me was to modify the "datestyle" attribute in postgresql.conf. 对我有用的是修改postgresql.conf中的“ datestyle”属性。 In my case it's located in /etc/postgresql/9.5/main/postgresql.conf 就我而言,它位于/etc/postgresql/9.5/main/postgresql.conf中

Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM