0
私は時間値を持つpostgresqlテーブルを持っていますが、タイムゾーン情報なしで保存されています。私はそれをUTC時間に変換したいが、それを特定の方法でフォーマットする。 どこかで構文エラーがあり、修正方法がわかりません。私は、次のSQLクエリがあります。タイムスタンプからUTC情報を削除する方法
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 /終了時刻フィールドに「00」の参照を削除したいです。 私はto_char関数()メソッドを使用して提案しているStackOverflowの上ここでは別のポストを見つけ、この例を使用:
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.
私が間違っていることはわかりません。
EDITそれが助け場合は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 |
は、なぜあなたは '使用しません"最初はUTC?列にタイムゾーンが含まれていません。 – pozs
@pozs UTC形式に変換する時間が必要です。他にどのようにそれを行うか分からなかった。もっと良い方法があれば、私はすべて耳です。 – Happydevdays