How to convert date time into unix epoch value in Postgres?

Solution 1:

If your data is stored in a column called ts, in a table called data, do this:

select extract(epoch from ts) from data

Solution 2:

To add Joe's answer, you can use date_part, i think it's syntax is clearer than 'extract'.

select date_part('epoch', ts) from data;