我有一个postgresql表,它有一个时间值,但它没有时区信息。我想将其转换为UTC时间,但请以特定方式格式化。 我在某处有语法错误,我不知道如何解决它。我有以下sql查询:
testdb=# select id, starttime at TIME ZONE 'UTC',endtime AT TIME ZONE 'UTC', dtc, etcd from fre order by id;
它会返回如下数据:
id | timezone | timezone | dtc | etcd
-------------+-------------+-------------+-----------+-------------------------
143322 | 13:00:00+00 | 00:00:00+00 | 0000000 | 8899703
990222 | 05:00:00+00 | 05:00:00+00 | 0000000 | 45007
452256 | 05:00:00+00 | 05:00:00+00 | 0000000 | 33303
123118 | 05:08:00+00 | 00:00:00+00 | 1111100 | 8899701
我想在starttime / endtime字段中删除“+00”引用。 我在stackoverflow上发现了另一篇建议使用to_char()方法的帖子,并使用了这个例子:
testdb=# select to_char(now(), 'HH24:MI:SS');
to_char
----------
09:55:48
(1 row)
所以我改编了它并尝试了这个:
testdb=# select to_char(now() AT TIME ZONE 'UTC', 'HH24:MI:SS');
to_char
----------
14:55:58
(1 row)
现在我正在尝试将此应用于原始查询,如下所示:
testdb=# select to_char(starttime AT TIME ZONE 'UTC', 'HH24:MI:SS') from fre;
ERROR: function to_char(time with time zone, unknown) does not exist
LINE 1: select to_char(starttime AT TIME ZONE 'UTC', 'HH24:MI:SS') f...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
我不确定我做错了什么。
编辑1
如果它有帮助...
testdb=# \d+ fre;
Table "public.fre"
Column | Type | Modifiers | Storage | Description
-----------+------------------------+-----------+----------+-------------
id | character varying(40) | not null | extended |
etcd | character varying(40) | not null | extended |
starttime | time without time zone | | plain |
endtime | time without time zone | | plain |
startdate | date | | plain |
enddate | date | | plain |
dtc | bit(7) | | extended |
答案 0 :(得分:0)
将其重新投放到没有时区的时间戳:
(starttime at TIME ZONE 'UTC')::timestamp without time zone