Re: How to build this field

From: Christof Glaser <gcg(at)gl(dot)aser(dot)de>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: How to build this field
Date: 2001-03-08 13:58:09
Message-ID: 0103081452400D.12945@pinguin
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi Juerg,

> I need to build an additional field (metakey) out of three fields in
> the table.
>
> SELECT a.a_kurzbez, a.a_ausgabenr, a.a_bundnr, a.a_nr, a.a_z_blaenge,
> a.a_z_laenge, a.a_z_umfang FROM auftrag a
>
> should be changed to something like
>
> SELECT (a.a_kurzbez + a.a_ausgabenr + a.a_bundnr) as metakey,
> a.a_kurzbez, a.a_ausgabenr, a.a_bundnr, a.a_nr, a.a_z_blaenge,
> a.a_z_laenge, a.a_z_umfang FROM auftrag a

Try the following:

SELECT
a.a_kurzbez || ' ' || a.a_ausgabenr::text || ' ' || a.a_bundnr::text
as metakey,
... remainder as above

or, if you need that frequently, create a function:

CREATE FUNCTION metakey (text, int4, int4) returns text as
' SELECT $1 || ' ' || text($2) || ' ' || text($3) '
LANGUAGE 'sql';

|| is the "concatenate text" operator.

Change the param types and cast them as you need.

Hope that helps,

Christof.

> output :
>
> field : metakey a_kurzbez a_ausgabenr
> a_bundnr
>
> DMD 001 03 DMD 001
> 03

--
gl.aser . software engineering . internet service
http://gl.aser.de/ . Planckstraße 7 . D-39104 Magdeburg
Tel. +49.391.7 44 77 10 . Fax +49.391.7 44 77 13 . Mobil 0177.77 92 84 3

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Frank Joerdens 2001-03-08 15:42:46 How to drop an <unnamed> trigger
Previous Message Karel Zak 2001-03-08 09:51:03 Re: No Documentation for to_char(INTERVAL, mask)