Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

16
  • 2
    @a_horse_with_no_name: OP asks for the best way to check if value is null or empty string. The trim() call is (comparatively) expensive - and just not necessary. I added more about char(n) and "empty string". Commented May 20, 2014 at 19:42
  • 1
    You wrote that any string expression containing only spaces is equal to '' . Can I remove trim and use coalesce(stringexpression,'')='' to check. This looks more readable to me compared to your answer.
    – Andrus
    Commented May 21, 2014 at 14:08
  • 1
    @Andrus: Yes, you can. I added that and some more to the answer. Commented May 21, 2014 at 14:54
  • 3
    select coalesce(' ', '') = '' returns false. So TRIM() is required
    – Andrus
    Commented May 21, 2014 at 18:17
  • 2
    Using (stringexpression = '') IS NOT FALSE is a bad advice because of poor readablity. It may be confusing for the reader as to what happens when stringexpression is NULL. Using coalesce fot this is a much better idea. Readability is important. If someone misunderstands your code it may result in a bug. A lot of code is read by multiple people, with varying experience, over multiple years.
    – godfryd
    Commented Mar 18, 2022 at 13:51