Modifying WHERE input conditions for a VIEW - Mailing list pgsql-novice

From Tony Holmes
Subject Modifying WHERE input conditions for a VIEW
Date
Msg-id 20030330141507.A83545@crosswinds.net
Whole thread Raw
Responses Re: Modifying WHERE input conditions for a VIEW  (Tom Lane <tgl@sss.pgh.pa.us>)
Export content of a DB  (Ben Clewett <B.Clewett@roadrunner.uk.com>)
List pgsql-novice
Hi,

I'm stuck with some libraries that severely limit how queries are formed
and sent to postgresql and decided to use views and rules to solve my
problem. However, I've bumped my head on an issue.

I have 2 tables that need to be selected from, depending on the input
WHERE condition.

Here is their very simplified schema:

table foo_users (
  uid serial,
  username character varying(16),    -- No @domainname.com
  password character varying(16),
  active boolean default 't'
);

table domain_users (
  uid serial,
  username character varying(255),    -- Includes @domainname.com
  password character varying(16),
  active boolean default 't'
)

Now, I'm dealing with pgsql commands (from an imap system FYI) that always
appends @domain.com to the username for the where clause:

  SELECT username, password FROM xxxx WHERE username='user@domain.com';


What I want to accomplish is, if the WHERE clause matches @foo.com
I want to select from foo_users, removing @foo.com, otherwise, return
the data from domain_users.

I have experimented with views, rules and looking all over the place
and am stuck!

How can I accomplish this?

Thanks in advance for you assistance!

--
Tony Holmes

Founder and Senior Systems Architect
Crosswinds Internet Communications Inc.


pgsql-novice by date:

Previous
From: Don Patou
Date:
Subject: database2uml software
Next
From: Tom Lane
Date:
Subject: Re: Index behavior question