I would like to check an input (parameter) of a stored procedure if it has many spaces and empty, not just 1 space like so:
' '
‘.
I tried :
IF column IS NULL or TRIM(column IS NULL) THEN RAICE NOTICE 'input is empty spaces';
END IF;
But the spaces input still passes through.
2
Answers
You could use
COALESCE()
here:The pattern
^s*$
will match zero or more whitespace characters. The outer call toCOALESCE()
replacesNULL
column values with empty string, which will match the regex pattern.TRIM(column IS NULL)
should result in an error, becausecolumn is null
yields aboolean
andtrim()
doesn’t work on boolean values.Note that
trim()
will return an empty string if the input is only blank, notnull
(an empty string''
is something different thannull
)You can shorten the whole test to a single expression: