【发布时间】:2021-03-09 04:55:14
【问题描述】:
我有一个日期字符串 2020-10-14, 14:13:23,我想在 python 中将其转换为 timestamp with timezone 格式,以便我可以在我的 postgresql 表中删除具有此特定时间戳的行
请建议如何进行?
【问题讨论】:
标签: python-3.x postgresql timestamp timestamp-with-timezone
我有一个日期字符串 2020-10-14, 14:13:23,我想在 python 中将其转换为 timestamp with timezone 格式,以便我可以在我的 postgresql 表中删除具有此特定时间戳的行
请建议如何进行?
【问题讨论】:
标签: python-3.x postgresql timestamp timestamp-with-timezone
你想cast吗?
select '2020-10-14, 14:13:23'::timestamp with time zone
|时间戳 |
| :--------------------- |
| 2020-10-14 14:13:23+01 |
如果你想过滤与这个字面值属于同一秒的时间戳:
select *
from mytable
where execution_date >= '2020-10-14, 14:13:23'::timestamp with time zone
and execution_date < '2020-10-14, 14:13:23'::timestamp with time zone + interval '1 second'
【讨论】:
select '2020-10-14, 14:13:23'::timestamp with time zone from table_name,我得到了 16 行,但实际上该表只包含带有此时间戳的两行。我做错了吗?
select * from table_name where execution_date in (select '2020-10-14, 14:13:23'::timestamp with time zone),但它返回0行。 execution_date 是上图中的列名