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.

Commentaires

Posts les plus consultés de ce blog

Install Xilinx ISE 14.7 on Ubuntu (Kubuntu) 20.04

The right features for the right market