Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id B8AD2633AE7 for ; Thu, 31 Dec 2009 12:24:02 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 53608-04-2 for ; Thu, 31 Dec 2009 16:23:52 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-yw0-f204.google.com (mail-yw0-f204.google.com [209.85.211.204]) by mail.postgresql.org (Postfix) with ESMTP id 3A32F633C43 for ; Thu, 31 Dec 2009 12:23:51 -0400 (AST) Received: by ywh42 with SMTP id 42so10258505ywh.28 for ; Thu, 31 Dec 2009 08:23:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=VOLy1I74muMvJpv1yUIJ20DyB1LFvL4n0fOJ4USE9y0=; b=g2zsSsAb803C79OVrg8msHiy8J6U2Gf01Ag6SqZ/0E+z1tcXk5O0wV5LjUeNdzOPTS xdTv894ZT6RGCIewN+CvVrbOK+V+/Ybw5gx5/p8AcrbZQHQKvyW7jqZ85b5iT3ui5IUG lO1dCplvchv/0SyLAz5loW6CK9pTz5IAmgQbY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=mG3W9yJtdUGTqIhqvM7A2osojJKdnbuseW5tgEB6DA3PwS29Wj5/IoUB8Sl5Gywotj z44CdaRMdVbilcGL2yLynsf+m0TK+D6ekijAmZ/0Z8kOkwZxDsphHmR6TyY0NgBVVfWs YpO6tTDt4xL/kSFMUOW3bUrhRQyKDeUPemCwA= MIME-Version: 1.0 Received: by 10.91.162.31 with SMTP id p31mr10049224ago.121.1262276630024; Thu, 31 Dec 2009 08:23:50 -0800 (PST) In-Reply-To: <4B3A9448.20308@obviously.com> References: <4B31D619.1090706@obviously.com> <4B31D86D.9030000@postnewspapers.com.au> <37d451f70912231304i3515e575x69b31638962739a6@mail.gmail.com> <4B32DB14.6080308@postnewspapers.com.au> <4B3A9448.20308@obviously.com> Date: Thu, 31 Dec 2009 09:23:49 -0700 Message-ID: <37d451f70912310823y114ff7a7xd511ae4f5d369e2d@mail.gmail.com> Subject: Re: Using || operator to fold multiple columns into one From: Rosser Schwarz To: Bryce Nesbitt Cc: sql pgsql , Craig Ringer Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.599 tagged_above=-10 required=5 tests=BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 200912/92 X-Sequence-Number: 33530 On Tue, Dec 29, 2009 at 4:44 PM, Bryce Nesbitt wrote= : > Craig is correct in the OP attempt. =A0 All but one field is intended to = be null Ah; my misunderstanding, then. Sorry for the noise. > Duplicate rows, or data in multiple columns, would wreck havoc on the > scheme. =A0If there is a better way, I am all eyes. One thought would be to add a couple of constraints: a CHECK constraint to ensure that one and only one of the columns is populated (think "t_number IS NOT NULL AND t_string IS NULL AND t_boolean IS NULL AND t_date IS NULL OR..."), and a UNIQUE constraint against (context_key, t_number, t_string, t_boolean, t_date). That's not really a "better" way, but it should prevent both duplicate and "compound" data. rls --=20 :wq