简体   繁体   English

postgres - 转换时间戳格式列表

[英]postgres - cast timestamp format list

In postgres when i do cast(varchar_col as timestamp) how do i know which formats (ie yyyymmdd, yyyy-mm-dd...etc) are supported?在 postgres 中,当我执行 cast(varchar_col 作为时间戳)时,我如何知道支持哪些格式(即 yyyymmdd、yyyy-mm-dd...等)?

Not great research on your end, because it's right there in the Postgres 8.4 docs in the section of the eponymous name:对你来说不是很好的研究,因为它就在同名部分的 Postgres 8.4 文档中:

https://www.postgresql.org/docs/8.4/datatype-datetime.html https://www.postgresql.org/docs/8.4/datatype-datetime.html

Valid input for the time stamp types consists of the concatenation of a date and a time, followed by an optional time zone, followed by an optional AD or BC.时间戳类型的有效输入包括日期和时间的串联,后跟可选的时区,再后跟可选的 AD 或 BC。 (Alternatively, AD/BC can appear before the time zone, but this is not the preferred ordering.) (或者,AD/BC 可以出现在时区之前,但这不是首选顺序。)

So, you need to combine all input format entries from the "Date Input" table and from the "Time Input" table, which are too many to list sensibly in an answer.因此,您需要组合“日期输入”表和“时间输入”表中的所有输入格式条目,这些条目太多而无法在答案中合理列出。 Makes no sense either – that's what official documentation is for.也没有意义——这就是官方文档的用途。

For a more comprehensive documentation on how dates and times are parsed from strings, that's officially documented as well:有关如何从字符串中解析日期和时间的更全面的文档,也有官方文档:

https://www.postgresql.org/docs/8.4/datetime-input-rules.html https://www.postgresql.org/docs/8.4/datetime-input-rules.html

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

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