Nigel Bishop wrote:

     username     |            domain         |            sendto
+-------------+-------------------------------+-------------------------
-----

 Postmaster       | intthit08.uk.rabbit.com   | root
 root             | intthit08.uk.rabbit.com   | [EMAIL PROTECTED]
 stoat.griffin    | trusting.co.uk            | [EMAIL PROTECTED]
 stoat.griffin    | trusting.com              | [EMAIL PROTECTED]
 stoat.griffin    | rusty.co.uk               | [EMAIL PROTECTED]
 stoat.griffin    | rusty.com                 | [EMAIL PROTECTED]

 *                | trusting.com              | [EMAIL PROTECTED]
 *                | trusting.co.uk            | [EMAIL PROTECTED]
 *                | rusty.co.uk               | [EMAIL PROTECTED]
 *                | rusty.com                 | [EMAIL PROTECTED]

The query will have the username and domain passed in as variables.
If the username and domain exist then return the sendto
The bit I'm struggling with is if the username doesn't exist then return
the sendto where the domain exists

e.g.  username=fred (this doesn't exist) and domain=rusty.com then
return [EMAIL PROTECTED], [EMAIL PROTECTED],
[EMAIL PROTECTED]

So: if the username doesn't exist then you return ALL rows with a matching domain? Not just username="*"?

I'm guessing I've mis-understood and you just want username="*", which would be something like this:

SELECT sendto, 1 AS priority FROM tbl WHERE username=$1 AND domain=$2
UNION ALL
SELECT sendto, 2 AS priority FROM tbl WHERE username='*' AND domain=$2
ORDER BY priority
LIMIT 1;

Does that help at all?
--
  Richard Huxton
  Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

              http://archives.postgresql.org

Reply via email to