我的桌子上有时区的日期和时间。
date_time_table
+------------+--------------+
| date_t | time_tz |
+------------+--------------+
| 2016-05-13 | 23:00:00 -02 |
| 2016-05-14 | 13:00:00 +06 |
+------------+--------------+
之后我运行SQL查询' UTC'时间
SELECT timetz AT TIME ZONE 'UTC' FROM date_time_tz
结果是:
+--------------+
| time_tz |
+--------------+
| 01:00:00 +00 |
| 07:00:00 +00 |
+--------------+
我可以用time_tz编写SQL组合的date_t来计算日期吗?
我期望的结果是:
+------------+------------+
| date_time_tz |
+------------+------------+
| 2016-05-14 01:00:00 +00 |
| 2016-05-14 07:00:00 +00 |
+------------+------------+
我尝试:
SELECT concat(date_t , ' ' ,time_tz) AT TIME ZONE 'UTC' FROM date_time_table
但它不起作用。
答案 0 :(得分:2)
如果列属于date
和time
类型:
select (current_date + current_time) at time zone 'UTC';
timezone
----------------------------
2016-07-12 12:06:00.239396
如果这些列是文本:
select ('2016-01-01'::date + '23:00:00 -02'::timetz) at time zone 'UTC';
timezone
---------------------
2016-01-02 01:00:00
答案 1 :(得分:0)
SELECT concat(date_t , ' ' ,time_tz)::timestamp AT TIME ZONE 'UTC' FROM date_time_table
尝试像这样投射