clear markdown compare help best fiddles feedback dbanow.uk
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 2805483 fiddles created (40770 in the last week).

-- empty string equals any string of spaces when cast to char(n) SELECT ''::char(5) = ''::char(5) AS eq1 ,''::char(5) = ' '::char(5) AS eq2 ,''::char(5) = ' '::char(5) AS eq3;
eq1 eq2 eq3
t t t
 hidden batch(es)


-- Test for "null or empty string" with char(n) SELECT stringexpression ,stringexpression = '' AS simple_test ,(stringexpression = '') IS NOT FALSE AS test1 ,(stringexpression <> '') IS NOT TRUE AS test2 ,coalesce(stringexpression, '') = '' AS test_coalesce1 ,coalesce(stringexpression, ' ') = ' ' AS test_coalesce2 ,coalesce(stringexpression, '') = ' ' AS test_coalesce3 FROM ( VALUES ('foo'::char(5)) , ('') , (NULL) , (' ') -- not different from '' in char(n) ) sub(stringexpression);
stringexpression simple_test test1 test2 test_coalesce1 test_coalesce2 test_coalesce3
foo f f f f f f
t t t t t t
t t t t t
t t t t t t
 hidden batch(es)


-- Test for "null or empty string" with text SELECT stringexpression ,stringexpression = '' AS simple_test ,(stringexpression = '') IS NOT FALSE AS test1 ,(stringexpression <> '') IS NOT TRUE AS test2 ,coalesce(stringexpression, '') = '' AS test_coalesce1 ,coalesce(stringexpression, ' ') = ' ' AS test_coalesce2 ,coalesce(stringexpression, '') = ' ' AS test_coalesce3 FROM ( VALUES ('foo'::text) , ('') , (NULL) , (' ') -- different from '' in a sane character type like text ) sub(stringexpression);
stringexpression simple_test test1 test2 test_coalesce1 test_coalesce2 test_coalesce3
foo f f f f f f
t t t t f f
t t t t f
f f f f f f
 hidden batch(es)