Using Views - Mailing list pgsql-general

From Christopher Browne
Subject Using Views
Date
Msg-id m31xrqbj3p.fsf_-_@wolfe.cbbrowne.com
Whole thread Raw
In response to Re: Triggers, Stored Procedures, PHP. was: Re: PostgreSQL Advocacy, Thoughts and Comments  ("Jason Tesser" <JTesser@nbbc.edu>)
Responses Read-only column  (Claudio Succa <claudio.succa.ml@pertel.it>)
List pgsql-general
After a long battle with technology, shane.dawalt@wright.edu (Shane D), an earthling, wrote:
>    That sounds find if all you want to do is to populate your
> drop-down list box with selection choices or use the same search
> criteria each time.  But if I want to access certain information for a
> particular customer that requires joins and the like, then a view
> would be great. But as far as I know, I am unable to place search
> parameters into a view.  Is this false or am I totally missing the
> point of views?

A VIEW is essentially "macroexpanded" into being the query requested,
in more-or-less the manner LISP handles macro expansion.

Suppose I define a view...

  create view january_transactions as
     select * from transaction_table where trans_on between
         '2003-01-01' and '2003-02-01';

I can then narrow things down when I use the view...

  select * from january_transactions  -- So I'm looking only at Jan
    where txn_type in (1, 2, 4);

If there's a "parameter" that you're expecting to use, then that means
that's a field you want to make sure you are selecting so that, when
you use the view, you can throw in a WHERE clause to specify the
"parameter."  That's what the "where txn_type in (1,2,4)" part
expresses.

One of the guys I work with is building "data warehouse" application
code; I keep commending that he use VIEWs as much as possible, and
building summary tables only when performance dictates it.  And the
way to define the views most usefully is to make them fairly generic.

In most cases, that means that the VIEW should JOIN tables together to
extract useful information.  And anything that could be a parameter
should be selected.  That way, filtering can be done on the view, and
so the view can be used for multiple reports.
--
output = reverse("moc.enworbbc" "@" "enworbbc")
http://www3.sympatico.ca/cbbrowne/linuxxian.html
"Heuristics (from the  French heure, "hour") limit the  amount of time
spent executing something.  [When using heuristics] it shouldn't take
longer than an hour to do something."

pgsql-general by date:

Previous
From: Randolf Richardson
Date:
Subject: Re: ip of the user doing an insert
Next
From: Peggy Go
Date:
Subject: I need your help. I'm confused with the files ...