postgres casting text to integer
If you want to cast a text field to integer, but some of your records are empty, here is a solution to avoid the : invalid input syntax for integer: '' error. Simply put a '0' at the beginning of your cast like this : ('0' || text_field)::integer. All empty fields will be equal to 0, and the others begins with 0 and convert without any problem to integer.