Re: Concatenation in SELECT

From: Manfred Koizar <mkoi-pg(at)aon(dot)at>
To: Alex <alex(at)meerkatsoft(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Concatenation in SELECT
Date: 2003-11-21 14:05:05
Message-ID: dv5srvom8fi7vog260mun6oukreh3cu78r@email.aon.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, 21 Nov 2003 20:22:17 +0900, Alex <alex(at)meerkatsoft(dot)com> wrote:
>Hi,
>is it possible to concatenate two rows (same or different data type)
>into one.
>like First Name, Last Name or ZIP City etc.

If you meant to concatenate two *columns*, it goes like

SELECT firstname || ' ' || lastname AS fullname FROM ...

or for nullable columns

SELECT coalasce(firstname || ' ', '') ||
coalesce(lastname, '') AS ...

This should work for non-text datatypes as well, because most, if not
all, datatypes have implicit casts to text.

Servus
Manfred

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Oleg Bartunov 2003-11-21 14:13:15 Re: tsearch2 column update produces "word too long"
Previous Message Markus Seibold 2003-11-21 14:04:22 Open source data modeling tools for PostgreSQL