From: Matt K <matt@kynx.org>
To: David Goodenough <david.goodenough@btconnect.com>
To: pgsql-general@postgresql.org
Subject: Re: SQL query
Date: Fri, 11 Feb 2005 11:31:38 +0000
Message-ID: <420C979A.8070109@kynx.org> (raw)
In-Reply-To: <200502111107.25004.david.goodenough@btconnect.com>
References: <200502111107.25004.david.goodenough@btconnect.com>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: matt@kynx.org, david.goodenough@btconnect.com
Subject: Re: SQL query
In-Reply-To: <420C979A.8070109@kynx.org>
References: <200502111107.25004.david.goodenough@btconnect.com> <420C979A.8070109@kynx.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox