Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id D1BE49F9F7D for ; Mon, 22 Jan 2007 04:24:10 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-new, port 10024) with ESMTP id 24611-07 for ; Mon, 22 Jan 2007 04:24:06 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.183]) by postgresql.org (Postfix) with ESMTP id 7FE3E9F9F10 for ; Mon, 22 Jan 2007 04:24:05 -0400 (AST) Received: from [194.25.154.138] (helo=webserv.wug.de) by mrelayeu.kundenserver.de (node=mrelayeu6) with ESMTP (Nemesis), id 0ML29c-1H8uTD2alO-0006ca; Mon, 22 Jan 2007 09:24:04 +0100 Received: from kretschmer by webserv.wug.de with local (Exim 3.36 #1) id 1H8uTC-00083D-00 for pgsql-sql@postgresql.org; Mon, 22 Jan 2007 09:24:02 +0100 Date: Mon, 22 Jan 2007 09:24:02 +0100 From: "A. Kretschmer" To: pgsql-sql@postgresql.org Subject: Re: list variable attributes in one select Message-ID: <20070122082402.GA27409@a-kretschmer.de> References: <20070122074348.GA8177@apartia.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20070122074348.GA8177@apartia.fr> X-OS: Debian/GNU Linux - weil ich es mir Wert bin! X-Message-Flag: "Windows" is not the answer. "Windows" is the question and the answer is "no"! User-Agent: Mutt/1.5.9i X-Provags-ID: kundenserver.de abuse@kundenserver.de login:51ea9561fc3f6d9539a2acd743e4748c X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200701/97 X-Sequence-Number: 27249 am Mon, dem 22.01.2007, um 8:43:48 +0100 mailte Louis-David Mitterrand folgendes: > "person_type" contains differents caracteristics for a person (actor, > director, author, etc.) who can have several types, hence the need for > the person_to_type table. > > I'd like to know if I can list in one SELECT command a person and all of > its types, given that the number of types can be 0 to n. > > For example, for a given person I'd like to obtain: > > "John Doe", "actor", "playright", "author" > > or > > "Jane Doe", "director" > > in one select. Yes, imagine, you have 2 tables: test=*# select * from f1; id | name ----+------ 1 | foo 2 | bar 3 | batz (3 rows) test=*# select * from f2; i_id | f1_id ------+------- 1 | 1 1 | 2 2 | 1 2 | 2 2 | 3 (5 rows) f1 contains your characteristics, f2 contains the assignment person -> characteristics. Now you can see all characteristics for person with id=1: test=*# select array_to_string(array(select name from f1 where id in (select f1_id from f2 where i_id = 1)), ', '); array_to_string ----------------- bar, foo (1 row) Hope that helps, Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header) GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net