I need to convert timestamp values to epoch in a SELECT
query.
Please find the below sample table and expected result.
Sample table:
select
Use the extract() function:
select id, extract(epoch from time) as time,
data1, data2,data3
from log;
Apparently your column is not a timestamp column but a varchar
, so you first need to cast that to a real timestamp before you can use extract()
select id,
extract(epoch from time::timestamp) as time,
data1, data2,data3
from log;
This will only work if all values in that column have the correct ISO format for a timestamp.
This teaches you, that you should
varchar
column!