typecast字符串到整数 - Postgres [英] typecast string to integer - Postgres
问题描述
我从一个在Varchar中有原始Feed的表中导入数据,我需要将一个varchar中的列导入到一个字符串列中。我尝试使用< column_name> :: integer
以及 to_number(< column_name>,'9999999')
但我得到错误,因为有几个空字段,我需要检索它们为空或null到新的表。
I am importing data from a table which has raw feeds in Varchar, I need to import a column in varchar into a string column. I tried using the <column_name>::integer
as well as to_number(<column_name>,'9999999')
but I am getting errors, as there are a few empty fields, I need to retrieve them as empty or null into the new table.
请告诉我是否有相同的函数。
Kindly let me know if there is a function for the same.
推荐答案
野性猜测:如果您的值是空字符串,可以使用NULLIF替换为NULL:
Wild guess: If your value is an empty string, you can use NULLIF to replace it for a NULL:
SELECT
NULLIF(your_value, '')::int
这篇关于typecast字符串到整数 - Postgres的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!