UNIX タイムスタンプ (エポックからの秒数を表す整数) を含む列があります。それらは次のようになります1638888715
。関数を使用してこの int をタイムスタンプに快適に変換しto_timestamp()
、次のような出力に到達します。2021-12-07 13:51:55+00
24 時間の間のデータを選択しようとしています: 2021-12-01 00:00:00 と 2021-12-01 23:59:59
私のクエリは次のようになります。
SELECT to_timestamp(loggeddate), to_timestamp(trxdate), [column a], [column b], [column c], [column d]
FROM [this table]
where [column a] like 'some criteria'
or [column a] like 'some other criteria'
and loggeddate between to_timestamp('2021-12-01 00:00:00') and to_timestamp('2021-12-01 23:59:59')
私が得るエラーは次のとおりです。
ERROR: invalid input syntax for type double precision: "2021-12-01 00:00:00"
LINE 5: and loggeddate between to_timestamp('2021-12-01 00:00:00') a...
^
誰かが盲目的に明白なことを説明できますか?
:::EDIT1:::
to_timestamp
回答ありがとうございます。今との違いがよくわかりましたto_timestamp(double precision)
。整数は倍精度のタイムスタンプに変換されています (時間の最後にタイムゾーン +00 が存在します)。
クエリの最後の行は次のようになります。
loggeddate between to_timestamp('2021-12-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS') and to_timestamp('2021-12-02 00:00:00', 'YYYY-MM-DD HH24:MI:SS')
次のエラーが表示されます。
ERROR: operator does not exist: integer >= timestamp with time zone
LINE 5: and loggeddate between to_timestamp('2021-12-01 00:00:00', '...
^
私は、私が望むものを手に入れるための回避策を見つけることができました。選択を日時フィルターなしでビューに書き込むことにより、整数は、私の「before」ステートメントを使用して照会できる日時に変換されます。
CREATE VIEW trx_data as
SELECT to_timestamp(loggeddate), to_timestamp(trxdate), [column a], [column b], [column c], [column d]
FROM [this table]
where [column a] like 'some criteria'
or [column a] like 'some other criteria'
ビューをクエリします。
select * from trx_data
where "logged date" between '2021-12-06 00:00:00' and '2021-12-07 00:00:00'
order by "logged date"
出力は次のようになります。
"2021-12-06 00:00:02+00" "2021-12-05 23:00:01+00" "THIS EVENT TYPE" "THIS EVENT NAME" "THIS AREA" "THIS UNIT"
クエリを実行する前にデータをビューに書き込むのではなく、これをすべて 1 つのステップで実行できると便利です。同じ結果です。
乾杯
EDIT2 - 作業; SGiux、エイドリアン、バジルに感謝
作業クエリは次のようになります。
SELECT to_timestamp(loggeddate), to_timestamp(trxdate), [column a], [column b], [column c], [column d]
FROM [this table]
where [column a] like 'some criteria'
or [column a] like 'some other criteria'
and to_timestamp(loggeddate)
between to_timestamp('2021-12-01 00:00:00')
and to_timestamp('2021-12-02 00:00:00')