Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

PostgreSQL: Get date and time from unix string format field

I have such a query:

select
(featuremap ->> 'column.time:value')
from db.table;

This returns the unix timestamp as a string value. I tried several things:
E.g.:

select
extract(epoch from(featuremap ->> 'column.time:value'))
from db.table;

Which returns this error: ERROR: function pg_catalog.date_part(unknown, text) does not exist

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

And:

select
to_timestamp(featuremap ->> 'column.time:value')
from db.table;

which returns this error: ERROR: function to_timestamp(text) does not exist

What do I have to do in this case in order to get the date and time from the unix timestamp string/text field?

>Solution :

Use to_timestamp with a single epoch argument. Since the original type of the argument is text it needs to be first cast to a numeric type.

select
to_timestamp((featuremap ->> 'column.time:value')::double precision)
from db.table;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading