pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedHow to build this field
3+ messages / 2 participants
[nested] [flat]
* How to build this field
@ 2001-03-08 08:10 juerg.rietmann@pup.ch
2001-03-08 13:58 ` Re: How to build this field Christof Glaser <gcg@gl.aser.de>
0 siblings, 1 reply; 3+ messages in thread
From: juerg.rietmann@pup.ch @ 2001-03-08 08:10 UTC (permalink / raw)
To: pgsql-sql
Hi everybody
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
output :
field : metakey a_kurzbez a_ausgabenr
a_bundnr
DMD 001 03 DMD 001
03
Thanks for any help ... jr
============================================
PFISTER + PARTNER, SYSTEM - ENGINEERING AG
Juerg Rietmann
Grundstrasse 22a
6343 Rotkreuz
Switzerland
phone: +4141 790 4040
fax: +4141 790 2545
mobile: +4179 211 0315
============================================
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: How to build this field
2001-03-08 08:10 How to build this field juerg.rietmann@pup.ch
@ 2001-03-08 13:58 ` Christof Glaser <gcg@gl.aser.de>
0 siblings, 0 replies; 3+ messages in thread
From: Christof Glaser @ 2001-03-08 13:58 UTC (permalink / raw)
To: 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
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: How to build this field
@ 2001-03-08 17:13 Christof Glaser <gcg@gl.aser.de>
0 siblings, 0 replies; 3+ messages in thread
From: Christof Glaser @ 2001-03-08 17:13 UTC (permalink / raw)
To: pgsql-sql
Josh,
> > [ stuff deleted ]
> > 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.
>
> ... But keep in mind that if any of the above values are NULL, the
> whole expression will be NULL. If one or more of the columns allows
> NULLs, you will need a function that includes testing for NULL.
>
> -Josh Berkus
Thanks for the hint. COALESCE is your friend, then :)
Christof.
--
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
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2001-03-08 17:13 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-03-08 08:10 How to build this field juerg.rietmann@pup.ch
2001-03-08 13:58 ` Christof Glaser <gcg@gl.aser.de>
2001-03-08 17:13 Re: How to build this field Christof Glaser <gcg@gl.aser.de>
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