From: | "Nigel J(dot) Andrews" <nandrews(at)investsystems(dot)co(dot)uk> |
---|---|
To: | Tino Wildenhain <tino(at)wildenhain(dot)de> |
Cc: | Pgsql-General <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: concenation of strings and null values |
Date: | 2003-10-07 09:00:40 |
Message-ID: | Pine.LNX.4.21.0310070953430.5797-100000@ponder.fairway2k.co.uk |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Tue, 7 Oct 2003, Tino Wildenhain wrote:
> Hi,
>
> SELECT 'abc'::text || 'def'::text;
>
> returns 'abcdef' as we know.
>
> SELECT 'abc'::text || ''::text;
>
> returns 'abc'
>
> SELECT 'abc'::text || null::text;
>
> returns null
>
> The last example looks like a bug,
> but if it is intentionally so, its
> at least very annoying and inconvenient.
Looks correct to me. Sure, might be annoying but we'd rather have correctness I
think :)
What you're asking for the equivalent of is:
something1 || ???? || something3 to equate to: something1something3
which you obviously can't say in the general case because you don't know if
???? really is an empty string or in fact something much more significant as in
the example:
'do' || 'not' || 'concatinate'
Therefore the whole expression should evaluate to null otherwise you'd never
know you didn't actually know if you should or shouldn't concatinate.
>
> Can someone enlighten me if this is
> in accordance to some not so transparent
> rules of SQL92 or '99 and if so, how
> to work around this?
In this instance use coalesce() as in: SELECT 'abc' || coalesce(null,'');
--
Nigel J. Andrews
From | Date | Subject | |
---|---|---|---|
Next Message | Dieter Fischer (grid-it) | 2003-10-07 09:20:14 | Re: concenation of strings and null values |
Previous Message | Tino Wildenhain | 2003-10-07 08:40:49 | concenation of strings and null values |