Combining text fields - Mailing list pgsql-novice

From Doug Silver
Subject Combining text fields
Date
Msg-id 200310171646.19085.dsilver@urchin.com
Whole thread Raw
Responses Re: Combining text fields
Re: Combining text fields
List pgsql-novice
I just want to confirm that this is the correct behavior for the return value
when combining text fields together.  If one of the fields is NULL, then the
return value of field1+field2 also becomes NULL.  If this is correct, is the
proper way to get around this to use a default value of '' for such fields?

TIA

-doug

# create table test2 (street1 varchar(10),street2 varchar(10),id serial);
NOTICE:  CREATE TABLE will create implicit sequence 'test2_id_seq' for SERIAL
column 'test2.id'
CREATE TABLE
test=# insert into test2 (street1) values('123 main');
INSERT 832047 1
test=# select street1||' '||street2||'|' as street1,'|'||street2||'|' from
test2;
 street1 | ?column?
---------+----------
         |
(1 row)

test=# select street1||' '||street2||'|' as
street1,'|'||street1||'|,'|'||street2||'|' from test2;
test'#
test=# select street1||' '||street2||'|' as
street1,'|'||street1||'|','|'||street2||'|' from test2;
 street1 |  ?column?  | ?column?
---------+------------+----------
         | |123 main| |



pgsql-novice by date:

Previous
From: dbaxter7@yahoo.com (Dave)
Date:
Subject: Trouble creating a survey database
Next
From: Josh Berkus
Date:
Subject: Re: Combining text fields