如何转换Yyyy-MM-DDTHH:MM:SS.SSSS时间戳为Yyyy-MM-DD HH:MM:Postgres中的SS
问题摘要
我想转换和验证Yyyy-Mm-Ddthh中的时间戳:MM:SS.SSSSZ格式(例如:2022-06-15T08:27:00.5999z)在Postgres中。
我尝试了
select * from my_table WHERE my_date >= date_trunc('second', '2022-06-15T08:27:00.599Z'::timestamp)
select to_char(to_timestamp('2022-06-15T08:27:00.599Z','YYYY-MM-DD\"T\"HH24:MI:SS'),'YYYY-MM-DD HH24:MI:SS')
这些查询在db_fiddle中罚款,但是在Python和Postgres SQL运行时会出现错误。
面对错误
rror:teiid31100解析错误:遇到 “'2022-06-15T08:27:00.599z','yyyy-mm-dd“ t” t“ hh24:mi:ss), '[] yyyy [] - mm“在第1行,第672列。期望:”和“ |”之间。 | “在” | “是” | “喜欢” | “像_regex” | “不是” | “或” | “订单” | “类似” ... org.teiid.jdbc.teiidsqlexception:teiid31100解析 错误:遇到 “'2022-06-15T08:27:00.599z','yyyy-mm-dd“ t” t“ hh24:mi:ss), '[] yyyy [] - mm“在第1行,第672列。期望:”和“ |”之间。 | “在” | “是” | “喜欢” | “像_regex” | “不是” | “或” | “订单” | “类似” ...;执行查询时错误
我的需要
输入时间戳:2022-06-15 t 08:27:00.599 z
预期时间戳:2022-06-15 08:27:00
感谢您的支持。
Problem Summary
I would like to convert and validate the timestamp which is in YYYY-MM-DDTHH:mm:ss.SSSZ format (ex: 2022-06-15T08:27:00.599Z) in postgres.
I tried
select * from my_table WHERE my_date >= date_trunc('second', '2022-06-15T08:27:00.599Z'::timestamp)
select to_char(to_timestamp('2022-06-15T08:27:00.599Z','YYYY-MM-DD\"T\"HH24:MI:SS'),'YYYY-MM-DD HH24:MI:SS')
These queries are executing fine in db_fiddle but giving an errors while running in python and postgres SQL.
Facing errors
RROR: TEIID31100 Parsing error: Encountered
"'2022-06-15T08:27:00.599Z','YYYY-MM-DD"T"HH24:MI:SS),
'[]YYYY[]-MM" at line 1, column 672.Was expecting: "and" | "between"
| "in" | "is" | "like" | "like_regex" | "not" | "or" | "order" |
"similar" ...org.teiid.jdbc.TeiidSQLException: TEIID31100 Parsing
error: Encountered
"'2022-06-15T08:27:00.599Z','YYYY-MM-DD"T"HH24:MI:SS),
'[]YYYY[]-MM" at line 1, column 672.Was expecting: "and" | "between"
| "in" | "is" | "like" | "like_regex" | "not" | "or" | "order" |
"similar" ...;Error while executing the query nil
My need
Input timestamp : 2022-06-15T08:27:00.599Z
Expected timestamp : 2022-06-15 08:27:00
Appreciate your support.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我过分简化您的问题,请原谅我,但是简单的演员和
date_trunc
会做技巧吗?另一种选择是用
:: timestamp(0)
- 请参阅此另一个答案>答案< /代码>
。但这将返回不同的结果:
Forgive me if I am oversimplifying your question, but wouldn't a simple cast and
date_trunc
do the trick?An alternative is to round the seconds with
::timestamp(0)
- see this otheranswer
. But it would return a different result: