My column needs to store the output of a function that returns an integer or null, where null is a meaningful value such as 'unknown', while also having a null value for the column to mean unset/missing.
If the value were a three-valued boolean instead, I could see a potential solution being the use of a tinyint, where 0 codes for False, 1 for True, and 2 for 'unknown'; e.g. myCol TINYINT NULL
. But in the above case, the full range of the integer is unavailable for use, so to say.
Thus, the desired data type supports values: null, null('unknown'), and integer.
Is there a way to achieve this in a single column? If not, what would be the ideal solution? I guess adding another column. Altering the function in question is not an option unfortunately. Thanks.
Edit: thanks for the insights/solutions!
As per the comment: PostgreSQL
numeric
/decimal
can hold anythingsmallint
,int
,bigint
can, plus special valuesNaN
,Infinity
,-Infinity
, as well as the usualnull
. You can use any combination of those: demoint[]
, an integer array type could also map the statusesnull
, an empty array, an array with result