3

Postgres char(14) fields stores datetime withou separators like 20131124112907

How to add separators so that result is string in format

2013-11-24 11:29:07

I tried Denis answer using

to_timestamp(timestamp, 'YYYYMMDDHHMISS')::text as updated_at

but got exception

  Message=ERROR: 22007: hour "15" is invalid for the 12-hour clock
  Code=22007

  File=src\backend\utils\adt\formatting.c
  Hint=Use the 24-hour clock, or give an hour between 1 and 12.
Andrus
  • 26,339
  • 60
  • 204
  • 378

1 Answers1

12

You can convert it using to_date() or to_timestamp():

select to_timestamp('20131124112907', 'YYYYMMDDHH24MISS')

http://www.postgresql.org/docs/current/static/functions-formatting.html#FUNCTIONS-FORMATTING-DATETIME-TABLE

Denis de Bernardy
  • 75,850
  • 13
  • 131
  • 154