Re: string is sometimes null ?

From: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
To: Graeme Hinchliffe <graeme(dot)hinchliffe(at)zeninternet(dot)co(dot)uk>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: string is sometimes null ?
Date: 2004-09-30 14:34:14
Message-ID: 20040930073249.Q8163@megazone.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, 30 Sep 2004, Graeme Hinchliffe wrote:

> > If monthcurr or username are null, the above will be null.
> > Anything || NULL => NULL.
>
> AH! thanks sorted it now. That is not the behaviour I would have
> expected :)
>
> Is there a concatination operator that will not do this? IE
>
> if
>
> var1 || var2 || var3
>
> and var2 is null would result in just var1var3 ?

You can use coalesce as suggested... However, since you are building a
statement, think about what you want to do when either of those are NULL.
You might want to use an empty string, or perhaps instead of ='' you might
actually be wanting an IS NULL clause, etc...

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2004-09-30 14:35:21 Re: 7.3.4 vacuum/analyze error
Previous Message Kevin Barnard 2004-09-30 14:30:02 Re: Out of memory errors on OS X