3
我有兩列,一個名爲「日期」,另一個名爲「時間」。日期是日期數據類型,「時間」是字符數據類型。我使用下面的查詢選擇一個新的聯合時間戳列to_timestamp存儲時區數據
SELECT
to_timestamp(concat_ws(' ',air_date,air_time),'yyyy-MM-dd HH24:MI:SS') as datetime
FROM table1
這將返回正確的時間戳但「+00」時區。我想明確地告訴查詢時區在「EST5EDT」中,這樣我就可以在時區中獲得「+04」或「+05」。我試過以下,但收到一個錯誤
SELECT
to_timestamp(concat_ws(' ',air_date,air_time,'EST5EDT'),'yyyy-MM-dd HH24:MI:SS TZ') as datetime
FROM table1
ERROR: "TZ"/"tz"/"OF" format patterns are not supported in to_date
SQL state: 0A000
如何選擇與它所包含的EST5EDT時區信息時間戳列?
這並不奏效。當我這樣做時會發生什麼,它假定輸入日期時間在「UTC」,然後將其轉換爲「EST5EDT」。我需要postgres首先將輸入時間解釋爲「EST5EDT」,然後再進行轉換。 – syang
對不起,錯了,出於某種原因,我認爲'to_timestamp'返回'沒有時區的時間戳'。然而,你的格式是[timstamp input](https://www.postgresql.org/docs/current/static/datatype-datetime.html#DATATYPE-DATETIME-INPUT)的支持,所以你可以使用像'concat_ws( '',air_date,air_time,'EST5EDT'):: timestamptz'。 – Abelisto
根據這個返回'timestamp with time zone',至少在postgres 9.5中:https://www.postgresql.org/docs/9.5/static/functions-formatting.html –