Cast string to number, interpreting null or empty string as 0

后端 未结 4 1071
情话喂你
情话喂你 2021-02-05 00:31

I have a Postgres table with a string column carrying numeric values. I need to convert these strings to numbers for math, but I need both NULL values as well as em

4条回答
  •  孤城傲影
    2021-02-05 00:49

    Check if you query parameter is empty (accepts null, empty string or value):

    SELECT CAST(TO_JSON(NULLIF(:myParameter, NULL)) AS VARCHAR) IS NULL OR
       CAST(TO_JSON(NULLIF(:myParameter, NULL)) AS VARCHAR) IN ('""');
    

提交回复
热议问题