Modifying WHERE input conditions for a VIEW

From: Tony Holmes <tony(at)crosswinds(dot)net>
To: pgsql-novice(at)postgresql(dot)org
Subject: Modifying WHERE input conditions for a VIEW
Date: 2003-03-30 19:15:07
Message-ID: 20030330141507.A83545@crosswinds.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)domain(dot)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.

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Tom Lane 2003-03-30 19:24:58 Re: Index behavior question
Previous Message Don Patou 2003-03-30 15:42:50 database2uml software