Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id D3BF5D70727 for ; Wed, 27 Jun 2012 23:27:11 -0300 (ADT) Received: from nm4-vm0.bullet.mail.ac4.yahoo.com ([98.139.53.206]) by magus.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1Sk4Ro-0003Ct-7l for pgsql-sql@postgresql.org; Thu, 28 Jun 2012 02:27:10 +0000 Received: from [98.139.52.194] by nm4.bullet.mail.ac4.yahoo.com with NNFMP; 28 Jun 2012 02:26:54 -0000 Received: from [98.139.52.128] by tm7.bullet.mail.ac4.yahoo.com with NNFMP; 28 Jun 2012 02:26:54 -0000 Received: from [127.0.0.1] by omp1011.mail.ac4.yahoo.com with NNFMP; 28 Jun 2012 02:26:54 -0000 X-Yahoo-Newman-Id: 313733.76428.bm@omp1011.mail.ac4.yahoo.com Received: (qmail 754 invoked from network); 28 Jun 2012 02:26:54 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=DKIM-Signature:X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:References:In-Reply-To:Mime-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Cc:X-Mailer:From:Subject:Date:To; b=TsY4cQKQZvg3glTJFBVH7jo4D623iNjux+7j8vynKRSqnVBwEffJIjFGhhIWKYc3vsrHsw/ujiFy6+WAF+jV7xUTPJ1p6JayH2reD7CnLu1VnxV8jAmyXexBiShOI5bWPp4b5+joCK2cATUDLTEs0wKe12o3c8eYyLbo8m7JCIo= ; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1340850414; bh=Ya2A3aO16ZmKLMEJrTW2crATdKBMPTv3V+0y5MmarIE=; h=X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:References:In-Reply-To:Mime-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Cc:X-Mailer:From:Subject:Date:To; b=45kWs59vyNXMCHfIoDg7jDeE4hzhM7p923kCfv7c+224HcbJdHcBxRtLq07ZF7LR78EEA0Oe9ZNFLBHqX4AWJKrHmzBSgrw1uivvwRICA0mSykzgcPU5ShoUKukqOENcPjtpyvSPsCq2Z0Sbn9+/6KZLcdGjKDWJP114xc9Uaqc= X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: yRqV3OoVM1ntqYqgdqS5CT1saC0k9J5TnX9EMwztP8lbstg kRHCSxI9YEi_49.EGKlWOu7vcxivJWrwdNWQaWhJgCepoqxRXLZTlyUWzwyq fjtN0J0B4z9HqxiEMMvWZimi1rlQ_K..BItespaqdr5HNRcJ5Haxs5cta9ff gAz28z.iaRC7wsBshqYhUYfuA02D2XQ7hDH35K3wkjPAGV0Njbr47C126l0B RXw0.S5Yz9OkUz4vI3__KnIsI7XidtPFgKgkwcXryNG5O_AOxCyK_NGuUeVJ Gmq7t_uW_j9_fXdNq8yrmmfukV6rHpWxiU_3KHFP9HbbHD1EsjMeo1BkxHHp C8lQEwnxarQrAkMziGaHO9wYQEp6bchrLhVikShaLP8Fu9ciXv5jOoMPc9vC N27lm5108O6Se9.d9z4v6NcSShZ253Mm.bOSSOrR1m1.NVqdli9AyBZd.rIT 7E7koMpjXdX8xBvWT1ZCZkNNBhVSSMtAHAmeiaZSN5Njyvvfqs9AtI7UzSyY j81OD_GBP6i4C X-Yahoo-SMTP: mpGJl6eswBD2IBufoVEg0Pa8gg-- Received: from [192.12.17.101] (polobo@24.93.23.188 with xymcookie) by smtp108-mob.biz.mail.ac4.yahoo.com with SMTP; 27 Jun 2012 19:26:54 -0700 PDT References: <4FEBAE3D.4030202@gmx.net> In-Reply-To: <4FEBAE3D.4030202@gmx.net> Mime-Version: 1.0 (1.0) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Message-Id: <0FED835B-B0CB-4D1A-9C3D-7BC2F5BAB19B@yahoo.com> Cc: "pgsql-sql@postgresql.org" X-Mailer: iPad Mail (9B206) From: David Johnston Subject: Re: How to solve the old bool attributes vs pivoting issue? Date: Wed, 27 Jun 2012 22:26:52 -0400 To: Andreas X-Pg-Spam-Score: -2.0 (--) X-Archive-Number: 201206/79 X-Sequence-Number: 36733 On Jun 27, 2012, at 21:07, Andreas wrote: > Hi >=20 > I do keep a table of objects ... let's say companies. >=20 > I need to collect flags that express yes / no / don't know. >=20 > TRUE / FALSE / NULL would do. >=20 >=20 > Solution 1: > I have a boolean column for every flag within the companies-table. > Whenever I need an additional flag I'll add another column. > This is simple to implement. > On the other hand I'll have lots of attributes that are NULL. >=20 > Solution 2: > I create a table that holds the flag's names and another one that has 2 fo= reign keys ... let's call it "company_flags". > company_flags references a company and an id in the flags table. > This is a wee bit more effort to implement but I gain the flexibility to a= dd any number of flags without having to change the table layout. >=20 > There are drawbacks > 1) 2 integers as keys would probaply need more space as a boolean colu= mn. > On the other hand lots of boolean-NULL-columns would waste space, to= o. > 2) Probaply I'll need a report of companies with all their flags. > How would I build a view for this that shows all flags for any compa= ny? > When I create this view I'would not know how many flags exist at exe= cution time. >=20 >=20 > This must be a common issue. >=20 > Is there a common solution, too? >=20 >=20 You should look and see whether the hstore contrib module will meet your nee= ds. http://www.postgresql.org/docs/9.1/interactive/hstore.html David J.