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

I need to shift characters around in a character varying column in postgres

I have a column with date and timestamp stored as character varying, I need to join to another table that has the same dates (also stored as character varying) but in different positions.

IE is there a way to convert:

"2022/08/03 13:29:59" ----------> "03/08/2022 13:29:59" 

Thanks

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

>Solution :

The best way would be to change the data type of both columns, as timestamps shouldn’t be stored as text. If not possible, a simple cast would do:

SELECT 
  '2022/08/03 13:29:59'::timestamp,
  '03/08/2022 13:29:59'::timestamp;

      timestamp      |      timestamp      
---------------------+---------------------
 2022-08-03 13:29:59 | 2022-08-03 13:29:59
(1 row)

Demo: db<>fiddle

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