Received: from localhost (unknown [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 48F312E3EC5 for ; Fri, 21 Dec 2007 07:16:52 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 66516-07 for ; Fri, 21 Dec 2007 07:16:48 -0400 (AST) Received: from mail49.e.nsc.no (mail49.e.nsc.no [193.213.115.49]) by postgresql.org (Postfix) with ESMTP id EBE032E3B61 for ; Fri, 21 Dec 2007 07:16:47 -0400 (AST) Received: from [192.168.0.57] (062016190089.customer.alfanett.no [62.16.190.89]) (authenticated bits=0) by mail49.nsc.no (8.13.8/8.13.5) with ESMTP id lBLBGj76020395 for ; Fri, 21 Dec 2007 12:16:45 +0100 (MET) From: "Leif B. Kristensen" To: pgsql-sql@postgresql.org Subject: Re: Concatenation through SQL Date: Fri, 21 Dec 2007 12:16:45 +0100 User-Agent: KMail/1.9.7 References: <6C0CF58A187DA5479245E0830AF84F42337F97@poweredge.attiksystem.ch> In-Reply-To: <6C0CF58A187DA5479245E0830AF84F42337F97@poweredge.attiksystem.ch> X-Face: %iea8o"[SI'kMDS.`hz7lU=?\^lC9J-]CVjo; f{4-C:$?uVUEjyN~uYFn%*aH_c3d09U>=?utf-8?q?x=0A=09TXtaoj=7EMV=2E8PgG7hik9=3BcCT2N6+u?=@Y{wH\p3*_f~FH9k,Wi74e[_l%.7b^'zJ)8S'^G<(=?utf-8?q?=3D=0A=09zw8=5CPMC3=27=7BKl9=2EzL*ks!b6wA?=,c~'F`k&Vq|ELDGa|4 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200712/109 X-Sequence-Number: 29801 On Friday 21. December 2007, Philippe Lang wrote: >(SELECT CONCAT(name, ', ') FROM employees AS e where e.appointment_id > = appointments.id) AS employees >FROM appointments >------------------------------ > >... where CONCAT suggest we want to concatenate the variable inside, >with the separator ', ' inbetween. I've got a similar problem. My persons table has a number of fields for different name parts: given, patronym, toponym, surname, occupation, epithet. I've written a Plpgsql function that concatenates the full name, but it's big and ugly. I'd like something more elegant, like the Python or PHP join() function. I tried Andreas' suggestion like this: pgslekt=> select array_to_string(array(select given, patronym, toponym from persons where person_id=57), ' '); ERROR: subquery must return only one column Is there any way to accomplish this from Plpgsql? -- Leif Biberg Kristensen | Registered Linux User #338009 http://solumslekt.org/ | Cruising with Gentoo/KDE My Jazz Jukebox: http://www.last.fm/user/leifbk/