您可以使用
rpad和
lpad功能分别在右侧或左侧填充数字。请注意,这不适用于数字,因此您必须使用
::char或
::text将其强制转换为数字:
SELECt RPAD(numcol::text, 3, '0'), -- Zero-pads to the right up to the length of 3 LPAd(numcol::text, 3, '0'), -- Zero-pads to the left up to the length of 3FROM my_table

您可以使用
rpad和
lpad功能分别在右侧或左侧填充数字。请注意,这不适用于数字,因此您必须使用
::char或
::text将其强制转换为数字:
SELECt RPAD(numcol::text, 3, '0'), -- Zero-pads to the right up to the length of 3 LPAd(numcol::text, 3, '0'), -- Zero-pads to the left up to the length of 3FROM my_table