I am trying to parse dirty input into postgres tables. I have a problem with a ‘date’ field occasionally containing non-dates such as ‘00000000’ or ‘20100100’. pg refuses to accept these, and rightly so.
Is there a way to have postgres recognize invalid dates (or only valid dates, if that works better), so I can substitute a sensible default?
(I’ve considered building a table listing the dates I’m willing to accept, and use that in a sub-select, but that seems awfully inelegant.)
Cheers,
Jurgen
http://www.tek-tips.com/viewthread.cfm?qid=1280050&page=9
A more generic approach than the above:
Used like this:
Credited to the friendly dudes at the #postgresql irc channel. 🙂