From: Oliver Elphick <olly@lfix.co.uk>
To: Amanda Riera <amanda@labtie.mmt.upc.es>
Cc: pgsql <pgsql-sql@postgresql.org>
Subject: Re: Concatenate fields
Date: Wed, 11 Apr 2001 13:14:24 +0100
Message-ID: <200104111214.f3BCEP205618@linda.lfix.co.uk> (raw)
In-Reply-To: <amanda@labtie.mmt.upc.es> <3AD44079.FCFE4583@labtie.mmt.upc.es>
Amanda Riera wrote:
>I would like concatenate some fields to have all information in just
>one field. I'm doing this below:
>
>CREATE TABLE bill_2col AS
>SELECT bill.bill_id,
> (trim(text(bill.bill_number)) || ' | ' ||
> trim(text(provider.company)) || ' | ' ||
> trim(to_char(bill.issue_date,'MM/DD/YY')) || ' | ' ||
> trim(to_char(bill.amount,'9999999.99')) || ' pts') AS billdesc
>FROM bill, provider
>WHERE bill.provider_id = provider.provider_id
>ORDER BY bill.bill_id;
>
>When it finds some empty field, it makes all the new field empty, no
>matters
>if the other are empty or not.
In this case, empty means NULL. Any concatenation involving NULL returns
NULL; this is according to the standard.
Use COALESCE(field,'') to return an empty string if field is NULL, so
that no NULLs go into the concatenation.
--
Oliver Elphick Oliver.Elphick@lfix.co.uk
Isle of Wight http://www.lfix.co.uk/oliver
PGP: 1024R/32B8FAA1: 97 EA 1D 47 72 3F 28 47 6B 7E 39 CC 56 E4 C1 47
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C
========================================
"Is any one of you in trouble? He should pray. Is
anyone happy? Let him sing songs of praise. Is any one
of you sick? He should call the elders of the church
to pray over him...The prayer of a righteous man is
powerful and effective." James 5:13,14,16
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: olly@lfix.co.uk, amanda@labtie.mmt.upc.es
Subject: Re: Concatenate fields
In-Reply-To: <200104111214.f3BCEP205618@linda.lfix.co.uk>
References: <200104111214.f3BCEP205618@linda.lfix.co.uk>
* 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