Stylized line drawing of mark playing the flute

Converting a Unix timestamp to a real Postgres date

Let’s say you have a Postgres database with a table that looks like this:

See how unix_date field is a Unix timestamp?

Well what if we want to deal with it as an actual Postgres date type?

Turns out it’s pretty easy with the following SQL:

SELECT*, TIMESTAMP 'epoch' + unix_date * INTERVAL '1 second' as real_dateFROM mytable