date
とtime
種類
あなたDay
はタイプdate
であり、あなたの場合Time
のタイプがtime
の場合、非常に単純な解決策があります。
SELECT EXTRACT(EPOCH FROM (day + time));
あなたは(あなたのセッションのタイムゾーン設定に従って解釈される)timestamp [without time zone]
を取得するためにdate
とtime
を追加することができます。
厳密に言えば、エポックを抽出することは、あなたの質問自体とは無関係です。
date
+ time
の結果はtimestamp
になります。
文字列型
あなたが文字列リテラルまたはtext
/varchar
列、使用について話している場合:
SELECT EXTRACT(EPOCH FROM ('2013-07-18' || ' ' || '21:52:12')::timestamp);
または
SELECT EXTRACT(EPOCH FROM cast('2013-07-18' ||' '|| '21:52:12' AS timestamp));
あなたの形ませない仕事
SELECT EXTRACT(EPOCH FROM TIMESTAMP ('2013-07-18' || ' ' || '21:52:12'));
これは動作します:
SELECT EXTRACT(EPOCH FROM "timestamp" ('2013-07-18' || ' ' || '21:52:12'));
を私はthe manual about type castsを引用:
It is also possible to specify a type cast using a function-like syntax:
typename (expression)
However, this only works for types whose names are also valid as function names. For example, double precision
cannot be used this way, but the equivalent float8
can. Also, the names interval
, time
, and timestamp
can only be used in this fashion if they are double-quoted, because of syntactic conflicts. Therefore, the use of the function-like cast syntax leads to inconsistencies and should probably be avoided.
太字強調鉱山。
要点:最初の2つの構文バリアントの1つを使用します。
正確なデータ型を提供するのを忘れました。 –