X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 2DD388B9EA6 for ; Fri, 11 Feb 2005 11:31:57 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 83147-02 for ; Fri, 11 Feb 2005 11:31:46 +0000 (GMT) Received: from mail.tenerifeideas.com (ns1.tenerifeideas.com [69.55.225.182]) by svr1.postgresql.org (Postfix) with ESMTP id E77088B9B26 for ; Fri, 11 Feb 2005 11:31:45 +0000 (GMT) Received: from [192.168.0.100] (unknown [213.55.21.128]) by mail.tenerifeideas.com (Postfix) with ESMTP id C4398BD2079; Fri, 11 Feb 2005 03:31:38 -0800 (PST) Message-ID: <420C979A.8070109@kynx.org> Date: Fri, 11 Feb 2005 11:31:38 +0000 From: Matt K User-Agent: Mozilla Thunderbird 1.0 (X11/20041214) X-Accept-Language: en-us, en MIME-Version: 1.0 To: David Goodenough , pgsql-general@postgresql.org Subject: Re: SQL query References: <200502111107.25004.david.goodenough@btconnect.com> In-Reply-To: <200502111107.25004.david.goodenough@btconnect.com> X-Enigmail-Version: 0.89.5.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests= X-Spam-Level: X-Archive-Number: 200502/632 X-Sequence-Number: 73436 David Goodenough wrote: >I could do this by doing a select * from addresses where customer = ? >and type = 'billing', looking to see if there is a result row and if not >repeating the query with type = 'default', but that seems inelegant to >me. > > Use NULL to indicate that the customer type is default. Then you can query with: select * from addresses where customer = ? and coalesce(type, 'billing') = 'billing' If type is NULL, the comparison will be 'billing' = 'billing' - always true. If there's a bunch of non-null type addresses, you'll get the 'billing' one. http://www.postgresql.org/docs/8.0/interactive/functions-conditional.html#AEN12003 Matt