pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ragnar <gnari@hive.is>
To: Andreas Joseph Krogh <andreak@officenet.no>
Cc: pgsql-sql@postgresql.org
Subject: Re: [HACKERS] lower() not working correctly...?
Date: Fri, 15 Sep 2006 10:07:05 +0000
Message-ID: <1158314825.17224.190.camel@localhost.localdomain> (raw)
In-Reply-To: <200609150952.53956.andreak@officenet.no>
References: <200609150952.53956.andreak@officenet.no>

On fös, 2006-09-15 at 09:52 +0200, Andreas Joseph Krogh wrote:
> I have the following query:
> 
> select lower(firstname) || ' ' || lower(lastname) from person
> 
> firstname and lastname are VARCHAR
> 
> lower() returns NULL when firstname OR lastname is NULL, is this correct?

In fact, your problem has nothing to do with lower().

You probably did not expect the || operator
to return NULL when any of the operands is NULL

as seen in 
select firstname || ' ' || lastname from person

so , as someone else has already mentioned,
you should use coalesce.

gnari





view thread (7+ messages)

Message-ID: <1158314825.17224.190.camel@localhost.localdomain>
Permalink:  ../1158314825.17224.190.camel@localhost.localdomain/
Also on:    postgresql.org/message-id/1158314825.17224.190.camel@localhost.localdomain

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: gnari@hive.is, andreak@officenet.no
  Subject: Re: [HACKERS] lower() not working correctly...?
  In-Reply-To: <1158314825.17224.190.camel@localhost.localdomain>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox