Postgresql - How to detect field's base64 encoding

Viewed 19

A client for my company is switching from a concurrent's software to ours (medical data management). I'm tasked with transforming their old soft's data (a restored postgres UTF8 db) so it becomes compatible with ours. Most of the data is no problem, but on an attachment table I hit a snag where some of the attachments are encoded in base64 and some are not (seems to be a date thing, albeit inexact).
Basically, in the pieces_jointes table, there's a piece_jointecolumn where some of it is basic file binary dumps (think %PDF-1.4 %....) and some is base64 (JVBERi0xLjUN...) with no flags and no clear distinction between the two (and before you ask no it's not just pdf. There's tiff, etf, some jpeg, some rtf and I haven't seen it all). Now postgres is good, so there's a built-in decode function, but postgres is not perfect, so just selecting decode(piece_jointe) will give me errors on the rows with raw binary. Instead of. You know. Just dumping the field with no decoding.

Is there a way to detect beforehand whether the field is encoded to make a case when or am I SOL and going to have to make a try_decode(CLongBinary*) in my own code?

0 Answers
Related